Solved

Split/Trim Formula Help in Crystal Reports 2008

Posted on 2013-02-01
8
767 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 100

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

759 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