Solved

Split/Trim Formula Help in Crystal Reports 2008

Posted on 2013-02-01
8
754 Views
Last Modified: 2013-02-04
Hi and thanks,

I have a field (SalesClassDesp)that contains:

XG - Gift Sale
N - No Sale
XM - Multiple Sales
etc...

I want to Split/trim from both left and right of the "-"  That is one string for Left and another for Right.

So:
XG
N
XM

OR:
Gift Sale
Multiple Sales
No Sale

I have tried:
If IsNull({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}) Then "" Else
Split({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}, " ")[1]

But I get error:
A subscript must be between 1 and the size of the array


Please help and thanks
0
Comment
Question by:Amour22015
8 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
Comment Utility
Try ..

If IsNull({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}) or
trim({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}) = ""  then
 ""
Else
if instr({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}, "-")=0 then   //no '-' use the whole field
{TEMP_PWC_Report_SP_MAIN.SalesClassDesp}
else
Split({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}, "-")[1]
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Looks like it should work

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
Peter's formula should work for the left side.  You don't really need InStr, because if the delimiter isn't found, Split returns a 1 element array with the whole string, so [ 1 ] would still work.  But it's not a bad idea to include the check, since you would need it if you were looking for other elements and there was only 1.

 You might want to add Trim around the Split, to remove any leading or trailing spaces.


 But if you also want a formula that produces everything after the "-", you may need to use something slightly different.  Could the field have more than one "-"?  If so, using [ 2 ] would only give you the part in between the second and third "-".  In that case you could use InStr to get the position of the first "-" and Mid or Right to extract the characters after that.

 If you need something like that, just let us know exactly what you need.

 James
0
 

Author Comment

by:Amour22015
Comment Utility
I don't think this field is going to have another "-" in it.

Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Amour22015
Comment Utility
peter57r,

Now that takes care of the Left side of the "-" I am also looking for the Right side.

Thanks
0
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Same principle; but I've used "" if there's no '-'

If IsNull({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}) or
trim({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}) = ""  then
 ""
Else
if instr({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}, "-")=0 then   //no '-' -set to empty
""
else
Split({TEMP_PWC_Report_SP_MAIN.SalesClassDesp}, "-")[2]
0
 

Author Comment

by:Amour22015
Comment Utility
It looks like the only difference is [2]

Thanks
0
 

Author Closing Comment

by:Amour22015
Comment Utility
Great thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sql server lock cursor 13 39
SQL Select Prior Ship Date Data 2 27
SQL server 2008 SP4 29 31
Sql query to Stored Procedure 6 12
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now