Solved

Split/Trim Formula Help in Crystal Reports 2008

Posted on 2013-02-01
8
757 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
ID: 38844580
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
ID: 38845877
Looks like it should work

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
ID: 38846606
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
ID: 38851248
I don't think this field is going to have another "-" in it.

Thanks
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:Amour22015
ID: 38851269
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
ID: 38851283
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
ID: 38851354
It looks like the only difference is [2]

Thanks
0
 

Author Closing Comment

by:Amour22015
ID: 38851608
Great thanks
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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