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
 SQL Server Development (2000)
 Reverse charindex

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-08-29 : 07:53:15
Martín writes "Is there a way to search a word in a string beggining in the last char, I mean Is there a function like VB´s function "InstrRev" in SQL Server? or Can I do simulate this function?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-08-29 : 07:55:46
SELECT CASE WHEN CharIndex(search, string)>0 THEN
Len(string)-CharIndex(Reverse(search), Reverse(string))-Len(search)
ELSE 0 END
AS ReverseCharIndex FROM myTable


If you have SQL Server 2000 you can create a user-defined function to wrap that up for you.
Go to Top of Page
   

- Advertisement -