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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Trim a string from a particular character onwards? 2

Status
Not open for further replies.

ouzojd

Programmer
Jun 9, 2002
314
AU
I have a report where one of the fields it groups on contains values like SJY4/0 SJY4/4.5 SJY4/9.5 F5/2.5 and so on.

I want each record to show everything up to the / so that when I do my grouping everything that starts with SJY4 ends up in the same group. The detail in the report is hidden so as long as it ends up in the same group is the most important thing for me.

I dont think the Left() and Right() functions in SQL would work as there is different lengths from each end of the string where the slash occurs.
 
Left({yourField},4) would always return "SJY4" if the string starts with that. Isn't this what you want?

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
This'll get everything up to the first "/", regardless of its position, and if it doesn't contain a "/", it will return the entire string:

If InStr({Table.Field},"/") > 0 Then
Left({Table.Field}, InStr({Table.Field},"/" ) - 1)
Else
{Table.Field};

-dave
 
Thankyou both for your help, Davo was on the money (purple star for you) because the slash could be in a different character position. I was also unaware of the InStr function which I can see coming in handy.

Thanks again, you saved me a couple of hours work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top