cancel
Showing results for 
Search instead for 
Did you mean: 

Joining Multiple Field Values?

Former Member
0 Kudos

I have a multi-select field that returns values in the following format when viewed from a crystal report:

K1

B2

L5

I would like the report to display the values in the following format separated by a comma:

K1,B2,L5

Another non-crystal forum provided me with the following formula (applied as formula to the field's Display String) which produced a crystal error: "String length is less than 0 or not an integer."

Formula:


Local StringVar inString := {multiselectfieldname};
Local StringVar outString := "";
Local NumberVar i;
Local NumberVar j;

i:=Instr(inString, "-");
While i >  0 Do
(
outString := outString + Left(inString, i-1);
j := Instr(inString,chr(10));
inString := Right (inString, len(inString)-j);
i := Instr(inString, "-");
if i > 0 Then
outString := outString + ",");
);
outString

Nubie question:

1. What do I need to do to fix this error and return the format described above?

Thanks for any assistance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You mean multi select parameter field? if so then try this

join({?Parameter},",")

If not then try this

create a formula like

@Evaluate:

whileprintingrecords;
stringvar str;
str:=str+{field};

Place this formula in detail section and now create one more formula like

@Display:

whileprintingrecords;
stringvar str;

place this in footer section.

Regards,

Raghavendra

Former Member
0 Kudos

Thanks Raghavendra for responding.

Without any formulas, the current report prints:

F1

K4

L6

I had already tried your first suggestion (join,","); but I get an error "A string array is required here" when I attempted to compile the formula.

When I attempted your second suggestion (evaluate/Display formulas) I observed the following:

The first record returned the first value in the list (i.e., F1), but not the remaining values separated by commas (i.e., F1,K4,L6). All subsequent records returned the same value (F1), despite the fact that subsequent records had different initial values (e.g., J5, U9, R4) than the first record's initial value (F1).

Again thanks, any help would be greatly appreciated!

Former Member
0 Kudos

I ammeded another solution in the archive.

With no formulas, the report prints:

F1

K4

With the following formula I get the report results:

F1

K4,F1

K4

Formula:


Whileprintingrecords;
stringVar i:={parameter};
stringVar i;
i:=i+",  "+{parameter};

Can I fix my problem by amending the above code?

Thanks very much.

Former Member
0 Kudos

Hi Bill,

Try this formula

numberVar i;
stringVar str;
for i:=1 to count({?My Parameter}) step 1 do 
str:=str+totext({?My Parameter}<i>)+",";
str

Regards,

Raghavendra

Former Member
0 Kudos

Many thanks Raghavendra for your continued help/persistence.

I get a compile error "This field cannot be summarized" for the following formula line:

for i:=1 to count({my multiline field}) step1 do

My multiline field is a multi-select (multiline) field type.

Thanks for any help.

Former Member
0 Kudos

I thought it is a multi valued parameter.

How about writing the formula like this?

replace({field},chr(10),",")

Regards,

Raghavendra

Former Member
0 Kudos

Many many thanks for your help Raghavendra--that solved the problem perfectly!!!

Appreciate your assistance sooo much!

Bill

Answers (0)