Solved

Split function in Crystal Reports

Posted on 2014-01-09
5
9,372 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 100

Accepted Solution

by:
mlmcc earned 500 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 34

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
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.

758 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

23 Experts available now in Live!

Get 1:1 Help Now