How do I concatenate multiple fields

Posted on 2009-12-23
Last Modified: 2012-05-08
I have a situation pretty much identical to the one for post Q_21354613.html:
 I have a database table with the fields

STN0       LN                  Text
ST1           1                    Line 1 Text
ST1           2                    Line 2 Text
ST1           3                    Line 3 Text
ST1           4                    Line 4 Text

I want to concatenate the fields so I get the output :
STN0       Text.......
ST1         Line 1 Text Line 2 Text Line 3 Text Line 4 Text

The solution (Below) provided by Frodoman returns the message "A string can be at most 256 characters long."

Is there a way to get a longer result?

The previous solution from Frodoman:
I assume that you're grouping the report based on STN0 (If not then you probably will need to do so).  You can then use ST1 in your details section and create a formula in your details section like this:

shared stringVar sText;
sText := sText + ' ' + {table.ST1};

Now in the group footer create a formula to display the concatenated text:

shared stringVar sText;

And in the group header create a formula to reset it:

shared stringVar sText := '';
Question by:xmcier
    LVL 4

    Expert Comment

    what version of crystal?
    LVL 4

    Expert Comment

    version 8 and before have 256 character limit for string variables
    LVL 4

    Accepted Solution

    This is a little rought, but depending on if you can anticpate its length (and be sure it's less than, say, 1020 characters. . .

    Shared stringVar sText1, sText2, sText3, sText4;
    if length(sText1) + {table.ST1} >255 then
       if length(sText2) + {table.ST1} >255 then
          if length(sText3) + {table.ST1} >255 then
             if length(sText4) + {table.ST1} >255 then
                sText4="String too long to fit."
                sText4=sText4 +' ' + {table.ST1}
            sText3=sText3 +' ' + {table.ST1}
           sText2=sText2 +' ' + {table.ST1}
       sText1=sText1 +' ' + {table.ST1}

    Then make a separate section for sText1, sText2, etc.  Force each section to supress if sText1, 2 whatever, is = ' '

    There might be a more savvy do-loop that you can do, but I don't know how to macro-substitute a name of a variable, so this may be clunky but it'll work.  Warning:  This is off the top of my head (I didn't test it).  But some slight variation of this should work.


    Author Comment

    This question is for v8.5.

    I believe JR's solution is going to take care of the issue.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    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. …
    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now