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 2005 Forums
 Transact-SQL (2005)
 Help with patindex and charindex

Author  Topic 

moxon
Starting Member

6 Posts

Posted - 2007-09-21 : 10:15:06
Hi everibody,
I know that pathindex and charindex find the first ocurrence in a string, but how i can find the last ocurrence??
Example.
I got a string '¿¿this ¿¿is a ¿¿string??'

I need to know the position of the last '¿¿' without eliminate '¿¿' that are before the last....

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-21 : 10:18:59
[code]Select datalength(Column1) - charindex('?', reverse(Column1)) + 1[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

B0g
Starting Member

19 Posts

Posted - 2007-09-21 : 10:20:08
I think that you can use REVERSE() function before charindex.

Go to Top of Page

moxon
Starting Member

6 Posts

Posted - 2007-09-21 : 11:02:04
Thank guys, i modified a little but REVERSE works to me....
Go to Top of Page
   

- Advertisement -