0

How do I create a comma separated list in Crystal Reports?

For this example I will be using ACN as the field to convert into a comma separated list, though the principals involved can be used with other fields.

Your report (or sub-report) must include the relevant table(s). For this example the table will be Case_Agc.

First, create a formula to trim any white space out of the field you wish to use (I will name mine ACN):

-----

IF ISNULL({case_agc.acn}) OR LEN(TRIM({case_agc.acn})) = 0
THEN ""
ELSE TRIM({case_agc.acn})

-----

Next, Insert a Group into your report on the formula you just created.

Next, create a formula to build your comma separated list (I will name mine Accumulate):

-----

WHILEPRINTINGRECORDS;
GLOBAL STRINGVAR Chain;

IF {@ACN} = ""
THEN Chain := Chain
ELSE Chain := Chain + {@ACN} + ", "

-----

Next, place this formula into your report in the Group Header for the Group you created earlier.

Next, create a formula to display your comma separated list (I will call mine Display):

-----

WHILEPRINTINGRECORDS;
GLOBAL STRINGVAR Chain;

IF Chain = ""
THEN ""
ELSE LEFT(TRIM(Chain), (LEN(TRIM(Chain)) - 1))

-----

Next, place this formula into your report in the Report Footer (you may want to set the "Can Grow" property on this field).

Finally, suppress all unnecessary sections of your report, and possibly add one or more select criterion.

 

A copy of the crystal report template demonstrating this has can be downloaded below




CSL_Sample.rpt

0 comments

Please sign in to leave a comment.