?
Solved

Split/Trim Formula Help in Crystal Reports 2008

Posted on 2013-02-01
8
Medium Priority
?
776 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 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

In this article I will describe the Detach & Attach 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 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 video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 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