Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Split function in Crystal Reports

Posted on 2014-01-09
5
Medium Priority
?
11,454 Views
Last Modified: 2014-01-20
Hi,

I have a field that holds a string of data separated by a semi-colon ';'.  I need to split this string between 1 and 5 fields.  Once the string is split I will need to show each field that contains data in the report.  

Example of the strings:

Accelerations; Early
Accelerations; Early; Late
Accelerations; Early; Late; Recurrent
Early; Late; Variable; Recurrent

I want to display the split fields as:  
Field 1                                   Field 2                      Field 3                 Field 4
Accelerations                       Early                        
Accelerations                       Early                         Late                      
Accelerations                       Early                         Late                     Recurrent
Early                                      Late                          Variable              Recurrent
0
Comment
Question by:jul_to_cool
5 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 39768711
What is your database ?
The best way to handle this is on database side.
Here is an example hot to do this with SQLServer
http://www.codeproject.com/Questions/400165/how-to-split-in-sql-server

You may also use SQLExpressions to get each part of the string
0
 

Author Comment

by:jul_to_cool
ID: 39768772
I'm using Crystal Reports 2008.
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 39769753
You can use SPLIT to separate them into an array

HOw many might there be?

Formulas to do this
Formula1 - Name - DispField1
WhilePrintingRecords;
Global StringVar Array myStrings;

myStrings:= Split({YourField},';');
If UBound(myStrings) >= 1 then
     myStrings[1]

Open in new window


One formula for each string - Just change the 2 to 3, 4, 5, etc

Formula2 - Name - DispField2
WhilePrintingRecords;
Global StringVar Array myStrings;

If UBound(myStrings) >= 2 then
     myStrings[2]

Open in new window


mlmcc
0
 
LVL 35

Expert Comment

by:James0628
ID: 39770670
If you use formulas like the ones that mlmcc posted, you would also want to add the following line to the beginning of every formula except the first one:

 EvaluateAfter ({@DispField1});

 That's to make sure that each of the other formulas is evaluated after DispField1, because it sets the myStrings variable, and the other formulas get their values from myStrings.

 James
0
 

Author Closing Comment

by:jul_to_cool
ID: 39794742
Thanks guys!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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. …
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview

877 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