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
 General SQL Server Forums
 New to SQL Server Programming
 select where string contains substring

Author  Topic 

jokxx
Starting Member

17 Posts

Posted - 2007-10-17 : 06:17:00
i'm using sql server 2005 and i need the sql i can use to select rows where the string contains a substring (in access i used instr but now it tells me it's not a built-in function.

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-10-17 : 06:24:49
Hi,
you can use charindex function to search for a string.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-17 : 06:40:26
WHERE MyColumn LIKE '%Search String%'

is more likely to use any available index on MyColumn than if you use a function like CHARINDEX - especially if your Search String does not start with the "%" wildcard character [i.e. you are doing a Starts With search]

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-17 : 06:52:05
Can you post some sample data with expected output?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jokxx
Starting Member

17 Posts

Posted - 2007-10-17 : 06:54:28
works great. thx
Go to Top of Page
   

- Advertisement -