?
Solved

Concatenate rows of data by a common group

Posted on 2006-06-04
6
Medium Priority
?
394 Views
Last Modified: 2008-11-08
Hello, I'm using Crystal 8.5.  I've got a db with two columns - Region and Zip Code.  For each Region there are multiple Zip Codes.  I need to display all the zip codes for each region in 1 row.  For example:

NY-NJ-MA  23412
NY-NJ-MA  74657
NY-NJ-MA  38472
TX-LA-OK  09384
TX-LA-OK  01983
TX-LA-OK  28952
TX-LA-OK  37561
TX-LA-OK  04827
etc

Result would be:
NY-NJ-MA  23412, 74657, 38472
TX-LA-OK  09384, 01983, 28952, 37561, 04827, etc

There are about 30 regions and some regions have 60+ zip codes.  I tried to use variables where the details part added the next zip in the list to the last (with ", " in between), reset on each Region and the display in the Region footer.  This worked until the zips for each region became too long.  Any other suggestions...
0
Comment
Question by:angelnjj
  • 3
  • 3
6 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 16830248
Try this

Create formulas
In the report header
Name - DeclVars
Formula
Global StringVar strZipCodes1 := '';
Global StringVar strZipCodes2 := '';
Global StringVar strZipCodes3 := '';

Add a group on region

In the Region group header
Name - ClearVars
Formula
Global StringVar strZipCodes1;
Global StringVar strZipCodes2 ;
Global StringVar strZipCodes3;
strZipCodes1 := '';
strZipCodes2 := '';
strZipCodes3 := '';
{RegionField}

In the detail section
Name - BuildZipString
Formula
Global StringVar strZipCodes1;
Global StringVar strZipCodes2 ;
Global StringVar strZipCodes3;
if (len(strZipCodes1) < 245) then
   strZipCodes1 := strZipCodes1 & "," & {ZipCodeField}
else if (len(strZipCodes2) < 245) then
   strZipCodes2 := strZipCodes2 & "," & {ZipCodeField}
else if (len(strZipCodes3) < 245) then
   strZipCodes3 := strZipCodes3 & "," & {ZipCodeField}

in the Region group footer use 3 formulas
Name - DispZipString1
Formula
Global StringVar strZipCodes1;
if (len(strZipCodes1) > 0) then
  Right(strZipCodes1,2)
else
  " No Zip Codes"

Name - DispZipString2
Formula
Global StringVar strZipCodes2;
if (len(strZipCodes2) > 0) then
  Right(strZipCodes2,2)
else
  " "

Name - DispZipString3
Formula
Global StringVar strZipCodes3;
if (len(strZipCodes3) > 0) then
  Right(strZipCodes3,2)
else
  " "

That should allow you to handle about 35-40 per line or a total of 100 - 120
If you find you need more add a 4th one

mlmcc
0
 
LVL 1

Author Comment

by:angelnjj
ID: 16836368
I've created all the formulas and placed them in the indicated sections, but the results are all "No Zip Codes" and the buildstring result is the record with a "," in front.  It isn't adding one record the the end of the next.  I assume it should look like this:

NY-NJ-MA  23412
DETAIL:  NY-NJ-MA  23412, 74657
DETAIL:  NY-NJ-MA  23412, 74657, 38472
GF1:  DISPLAY Formula in Region Footer:  23412, 74657, 38472
DETAIL:  TX-LA-OK  09384
DETAIL:  TX-LA-OK  09384, 01983
DETAIL:  TX-LA-OK  09384, 01983, 28952
DETAIL:  TX-LA-OK  09384, 01983, 28952, 37561
DETAIL:  TX-LA-OK  09384, 01983, 28952, 37561, 04827
GF1:  DISPLAY Formula in Region Footer: 09384, 01983, 28952, 37561, 04827

Using the following, I got the right display results, but ran into the 254 character problem.  Is there any way to ammend what I have below to combine what you had to take care of the limit?  I'm not sure I understand the nuances of the BuildString to make the adjustments myself.

Thank you.
0
 
LVL 1

Author Comment

by:angelnjj
ID: 16836390
Forgot the formulas I tried to use at the beginning (from a little diggin in this forum)
//1)  {@Initialize} in GH1

WhilePrintingRecords;
StringVar chain := ', ';
NumberVar ChCnt := 1

//2)  {@Evaluate} in Details

WhilePrintingRecords;
StringVar Item:= TrimRight({ZIPGOOD.ZIPCode});
StringVar Chain;
NumberVar ChCnt;

If
  ChCnt = 1
Then
  (ChCnt:= 2; chain := Item)
Else
  chain := chain + ', ' + Item else ""

//3)  {@Display}

WhilePrintingRecords;
StringVar Chain

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 16838397
Sorry.  Forgot an important part

Add to the start of each formula

   WhilePrintingRecords;

mlmcc
0
 
LVL 1

Author Comment

by:angelnjj
ID: 16844603
YAY!!  Thank you SOOO much...
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 16847652
Glad i could help

mlmcc
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question