How do I concatenate multiple fields

Posted on 2009-12-23
Medium Priority
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
  • 2

Expert Comment

ID: 26113893
what version of crystal?

Expert Comment

ID: 26113963
version 8 and before have 256 character limit for string variables

Accepted Solution

jruhe earned 1000 total points
ID: 26114028
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

ID: 26114266
This question is for v8.5.

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

850 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