SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select where string contains substring
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jokxx
Starting Member

17 Posts

Posted - 10/17/2007 :  06:17:00  Show Profile  Reply with Quote
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

India
394 Posts

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

Kristen
Test

United Kingdom
22415 Posts

Posted - 10/17/2007 :  06:40:26  Show Profile  Reply with Quote
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

India
22761 Posts

Posted - 10/17/2007 :  06:52:05  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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 - 10/17/2007 :  06:54:28  Show Profile  Reply with Quote
works great. thx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.2 seconds. Powered By: Snitz Forums 2000