Print Page | Close Window

Multiple Fields into one string per group

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22753
Printed Date: 03 May 2024 at 6:01am


Topic: Multiple Fields into one string per group
Posted By: jessewithag
Subject: Multiple Fields into one string per group
Date Posted: 02 Apr 2019 at 8:18am

Hello,
I currently have a report with groups that look like the following:
1
                              
1000      02/01/19      02/08/19     31     REG     7         1
1000      01/01/19      02/08/19     30     REG     38        5
1000      12/01/18      02/08/19     29     REG     69        7
1000      11/01/18      02/08/19     28     REG     99        7
1000      10/01/18      02/08/19     27     REG     130      7
1000      09/01/18      02/08/19     26     REG     160      7
1000      08/01/18      02/08/19     25     REG     191      7

I would like to get the fields in the last column into the group header in a single field for each individual group, ex this group would return 1577777, the same as the list of records above in the last column so the data would read

1 1577777
                              
1000      02/01/19      02/08/19     31     REG     7         1
1000      01/01/19      02/08/19     30     REG     38        5
1000      12/01/18      02/08/19     29     REG     69        7
1000      11/01/18      02/08/19     28     REG     99        7
1000      10/01/18      02/08/19     27     REG     130      7
1000      09/01/18      02/08/19     26     REG     160      7
1000      08/01/18      02/08/19     25     REG     191      7

Any help is appreciated. Thanks.



Replies:
Posted By: kevlray
Date Posted: 03 Apr 2019 at 4:10am
I think of only two ways to do this.  One create a command that creates the string with SQL code (probably as a second data source).  Two create a subreport that creates the string and passes back the value to the main report.


Posted By: jessewithag
Date Posted: 03 Apr 2019 at 6:18am
Hello, I was able to resolve the issue after searching many different forums.

I had to add a variable to each group from header to details to footer that collected the fields while printing records in the group and then produced them into the Group Footer, instead of the Group Header.

GHeader:
WhilePrintingRecords;
StringVar ConcatenatedID;
If Not InRepeatedGroupHeader Then
    ConcatenatedID := "";

Details:
WhilePrintingRecords;
StringVar ConcatenatedID := ConcatenatedID + {Field};

GFooter:
WhilePrintingRecords;
StringVar ConcatenatedID;

This produced a string variable which I then reversed and changed to number, and then back to string so i could add leading zeroes. Also, in the records that were read and put into the string, I had some fields that were suppressed and still got picked up into the string. To resolve this I had to also create a formula to match the suppression conditions and changed the pulled field to a null value so my string wasn't affected.

Thanks for the assistance and advice, this is my first thread but I lurk quite a bit learning things here and there.


Posted By: kevlray
Date Posted: 03 Apr 2019 at 10:15am
I had thought of a solution like that, but was not sure if it would display properly.  Not sure why you would have to change it to a number then back to a string.  There are ways to format to get leading zeros on strings.


Posted By: jessewithag
Date Posted: 10 Apr 2019 at 6:24am
for some reason when i reloaded the report without saving data there was an error with the section of the formula highlights but showed no errors in checking the syntax. Not sure if doing the conversion all at once and calculating the field was too much for crystal but after i split it up, the false errors stopped.



Print Page | Close Window