Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how to find last occurrence of a pattern

Author  Topic 

Hommer
Aged Yak Warrior

808 Posts

Posted - 2007-01-05 : 12:22:15
Hi, all,

I am looking for some ways to return the last occurrence of a pattern in a specified expression. CharIndex gave me the first occurrence.
For instance, I need to get the position of the last space in this string:
'John E. Doe'

Thanks!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2007-01-05 : 13:32:44
[code]
Declare @str varchar(32)
Set @str = ' abc defghi j u'

SELECT Len(@str) + 1 - CharIndex(' ', Reverse(@str))
[/code]
Go to Top of Page

Hommer
Aged Yak Warrior

808 Posts

Posted - 2007-01-05 : 13:45:32
Great, thanks!
Go to Top of Page
   

- Advertisement -