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

How to locate last occurrence of character in string?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How to locate last occurrence of character in string?
 

In SQL 7 and 2000 you can use the following query.

Select
ColA,
Loc=Case charindex('a',reverse(ColA))
When 0 Then 0
Else 1+len(rtrim(ColA))-charindex('a',reverse(ltrim(ColA)))
End
From table

Or if you only want to see those strings that match, use this query.

Select
ColA,
Loc=1+len(rtrim(ColA))-charindex('a',reverse(ltrim(ColA)))
From table
Where charindex('a',reverse(ColA))>0 Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top