Solved

Parsing multi-valued fields in Crystal Reports

Posted on 2008-10-14
5
573 Views
Last Modified: 2012-06-21
I am pulling a multi-valued text string into Crystal Reports from a sql database.  The field is a comment field in which multiple values are entered into sql.  They are then stored in sql as a single text field, separated by: ý.
ie - teowtýCE.PHARM.TECH
I would like to take the text in this single Crystal Reports field and parse it out into two or more columns.
Column 1 = teowt
Column 2 = PHARM.TECH
Is there a way to do this in Crystal, or do I need to accomplish this via a SP on the SQL side?  I am not a promgrammer by any means, so dumb it down for me please !
Any help would be greatly appreciated.
0
Comment
Question by:cccpdavis
  • 3
  • 2
5 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 22712953
Yes, use the SPLIT function

Add a formula
WhilePrintingRecords;
Global StringVar Array CommentPieces;

CommentPieces := Split({YourField},'ý');
''

You can then use formulas to display each value
WhilePrintingRecords;
Global StringVar Array CommentPieces;

CommentPieces[1]

mlmcc
0
 

Author Comment

by:cccpdavis
ID: 22715347
First off, thanks for the response.
I attempted to run this process in Crystal and it throws errors relating to returning array values.  Right clicked on the field in the report and selected Format Field, then selected the formula icon next to the Display String details.  Not sure if I was executing that incorrectly or not.  
I then went into sql and executed the following:
Declare @SEC_COMMENTS    VARCHAR(100)
SET @SEC_COMMENTS = 'blahýblah'

SELECT SUBSTRING(@SEC_COMMENTS,1, NULLIF(CHARINDEX('ý', @SEC_COMMENTS) - 1, -1)) AS [COMMENT1],
         SUBSTRING(@SEC_COMMENTS, CHARINDEX('ý', @SEC_COMMENTS) +1, LEN(@SEC_COMMENTS)) AS [COMMENT2]

and it returns the text string that I specified in the correct format ('blahýblah'), but I cant figure out how to apply it to an actual data field to use in a query. Would I use this formula to create a stored procedure from which to generate a subset of data, or pass it directly in the query?  I am very new to all this (sql training coming in Feb) so now I am just trying to muddle through it on my own.  Thanks for any and all input.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
ID: 22715373
No.

In the Field Explorer
Right Click FORMULAS
Click NEW
Give it a NAME
Add the code
SAVE AND CLOSE

Use it like any other field from the database

mlmcc
0
 

Author Closing Comment

by:cccpdavis
ID: 31505942
Thanks a lot.
0
 

Author Comment

by:cccpdavis
ID: 22723986
Thanks a lot!  This worked great.  I figured out that the formula was one column, then I needed as many print columns as there were going to be delimiters.
Field 1 - WhilePrintingRecords;
Global StringVar Array CommentPieces;

CommentPieces := Split({YourField},'ý');
''

Field 2, etc........ -
WhilePrintingRecords;
Global StringVar Array CommentPieces;

CommentPieces[1]
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

929 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

13 Experts available now in Live!

Get 1:1 Help Now