Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim to second underscore 1

Status
Not open for further replies.

CRilliterate

Technical User
Dec 7, 2005
467
US
I have names like
A_1_WE_SILV
Q_2_UU
and I need to trim to before second underbar like A_1

How do I do that?

________________________________________
I am using Windows XP, Crystal Reports 9.0 with SQL Server
 
Left (searchfield, InStr (InStr (1, searchfield, "_") + 1, searchfield, "_") - 1)
 
All I did - I just replaced searchfield with actual field name, right?
I got:
'String lenght is less then 0 or not an integer'
and it is NOT an integer...it is a string.


Thanks mbutch, any thoughts about an error? I will go try to alter your formula if I could.

________________________________________
I am using Windows XP, Crystal Reports 9.0 with SQL Server
 
Yes, the formula is correct. It may be throwing an exception because you have either a null value in the field or some of the names don't have underscores. Try doing a check on the field first:

IF Not IsNull(searchfiled)
THEN formula
ELSE ""

If that isn't your problem, you will have to check to make sure the string containes underscores like

IF Not IsNull(searchfiled)
THEN
IF InStr(InStr(1, searchfield, "_") + 1, searchfield, "_") - 1 > 1
THEN formula
ELSE whatever you want to do instead
ELSE
 
Brilliant, thanks, working, have a star!!!!!!!!

________________________________________
I am using Windows XP, Crystal Reports 9.0 with SQL Server
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top