Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Concatenate Same Field Post Reply Post New Topic
Author Message
laknight
Newbie
Newbie


Joined: 15 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote laknight Replybullet Topic: Concatenate Same Field
     Posted: 22 Aug 2008 at 8:53am
Hello:  I have records which look like this:
 
ORDER_NO             TEXT
1234                       A    (with a carriage return)
1234                       B    (with a carriage return)
1234                       C    (with a carriage return)
 
I need to concatenate the TEXT field values into a string while stripping out the carriage returns and/or extra spaces for each value to look like this:
 
ORDER_NO             TEXT
1234                       A,B,C,   (etc... goes on infinitely)
 
I can not understand how this works. I've read the thread in this forum called "Concatenating Fields - Help???" which is similar to what I want to do, but it doesn't work for me and I'm not sure if I'm doing it wrong, or if it is because of the carriage returns.
 
I've also read on another posting about creating 3 formulas and displaying the resulting string in a group footer, but I can't get that to work either. Maybe I'm not placing the groups and formulas and fields in the right places.
 
Thanks for ANY help!
laknight
IP IP Logged
neinta
Newbie
Newbie


Joined: 26 Aug 2008
Location: United States
Online Status: Offline
Posts: 6
Quote neinta Replybullet Posted: 28 Aug 2008 at 3:07pm
Use this formula to remove the carriage return and extra spaces
   

{@REMOVE} - Removes the carriage return from the field, then trims the spaces.
    Trim (Replace ({Field}, chr(13), "" ))

{@Join1} - Suppressed in Details
    Shared stringVar Y:= {@REMOVE};
    Shared stringVar X;
    Shared stringVar Z;


{@Join2} - In details section displays the concatenated field
    EvaluateAfter ({@JOIN1});

    shared Stringvar X := {@Join1}; // Previous Record
    Shared stringVar Y:= {@REMOVE}; // Data without Carriage Return
    Shared StringVar Z;

    IF RECORDNUMBER = 1 THEN Z := Y ELSE Z:= X & "," & Y;

    Z

I did received an error about the maximum number of characters in a string being 65,534.


Edited by neinta - 28 Aug 2008 at 3:07pm
IP IP Logged
laknight
Newbie
Newbie


Joined: 15 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote laknight Replybullet Posted: 29 Aug 2008 at 9:50am
Thanks for your response. It is working close, but with one issue:
 
It has multiple joined detail records for each record. Is there a way to display the last record only? It looks like this now:
 
A
A,B
A,B,C
A,B,C,D etc...
laknight
IP IP Logged
neinta
Newbie
Newbie


Joined: 26 Aug 2008
Location: United States
Online Status: Offline
Posts: 6
Quote neinta Replybullet Posted: 04 Sep 2008 at 5:38am
You can copy {@Join2} to the footer.  Suppress it in the details.  This will give you the complete list in the footer.


If you are using groups and need to reset for each group make a new formula and place it in the header.

{@Reset}
    shared StringVar Z := "";

and replace the if statement in {@join2} with
    IF Z = ""  THEN Z := Y ELSE Z:= X & "," & Y;


IP IP Logged
mrc161
Newbie
Newbie


Joined: 27 Dec 2007
Location: United States
Online Status: Offline
Posts: 19
Quote mrc161 Replybullet Posted: 04 Sep 2008 at 10:00am

This is working perfectly for me (thank you!) - except for one thing.  I AM grouping in my report, and when I place Join2 in the footer, it's giving me what I need except it repeats the last item on the list.

So for example, if my result should be A,B,C, I'm getting A,B,C,C.  Or if it's A,B,C,D, I'm getting A,B,C,D,D.

Any idea why that last one is wanting to repeat?

IP IP Logged
laknight
Newbie
Newbie


Joined: 15 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote laknight Replybullet Posted: 08 Sep 2008 at 11:21am

I'm getting a duplicate last line also. Can anyone help?? I'm going to look at it further.

laknight
IP IP Logged
neinta
Newbie
Newbie


Joined: 26 Aug 2008
Location: United States
Online Status: Offline
Posts: 6
Quote neinta Replybullet Posted: 09 Sep 2008 at 2:30pm
Sorry, I didn't catch that when I tested it.  Add a new formula to put in footer (remove the old one).

{@Variable}
    shared StringVar Z;
   
       Z

This will prevent the duplicate at the end

IP IP Logged
laknight
Newbie
Newbie


Joined: 15 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote laknight Replybullet Posted: 11 Sep 2008 at 6:34am
Big%20smile Awesome! Thanks!
laknight
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum