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)
 Can CharIndex be like INSTR in Oracle?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-12-20 : 07:46:23
Lone Ranger writes "as we know in oracle we know INSTR function that can return char index as like function charindex in sql, but the diffrent is INSTR can find those char with the second, third, etc in the same string.


Example INSTR in Oracle:
instr('Tech on the net', 'e') would return 2; the first occurrence of 'e'

instr('Tech on the net', 'e', 1, 1) would return 2; the first occurrence of 'e'

instr('Tech on the net', 'e', 1, 2) would return 11; the second occurrence of 'e'

instr('Tech on the net', 'e', 1, 3) would return 14; the third occurrence of 'e'

instr('Tech on the net', 'e', -3, 2) would return 2.

Could you help me how to subtitute INSTR function in SQL."

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-20 : 07:57:11
If you want to find incremental occurence of particular word in string using CharIndex(), you should change start_location each time.

For e.g.

Select Charindex('Tech on the net', 'e', 1) -- return 2
Select Charindex('Tech on the net', 'e', 3) -- return 11
Select Charindex('Tech on the net', 'e', 12) -- return 14


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

- Advertisement -