Solved

Split/Trim Formula Help in Crystal Reports 2008

Posted on 2013-02-01
8
772 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 101

Expert Comment

by:mlmcc
ID: 38845877
Looks like it should work

mlmcc
0
 
LVL 35

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

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

Thanks
0
 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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