Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I would like to simplify the following code :
Load
Field_1 As Total_1,
Field_1 + Field_2 As Total_2,
Field_1 + Field_2 + field_3 AS Total_3,
I do have in total 25 different fields where i would like to save the sum to a new field.
Maybe i could loop through the field vales using a variable?
Any ideas on how to simplify this code?
You might try something like this:
SET field_names='Field1, Field2, Field3';
LET total_field_names='';
LET running_total='';
LET csv = chr(39) & Replace(field_names, ',', chr(39)&','&chr(39)) & chr(39);
LET counter=1;
for each value in $(csv)
If (len(total_field_names) > 0) then
LET total_field_names = total_field_names & ',';
LET running_total = running_total & '+';
ENDIF
LET running_total = running_total & value;
LET total_field_names = total_field_names & running_total & ' AS Total' & counter;
LET counter = counter + 1;
next value
LOAD
$(total_field_names)
Resident
table_name;