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)
 find if column records are substring of a string

Author  Topic 

rotemblu
Starting Member

2 Posts

Posted - 2010-01-15 : 04:52:15
for example if I have the table:
column1 column2
thisisstring1 thisisstring2
thisisstring3 thisisstring4

and I enter the text "the thisisstring1 is a substring of of this string"
and it will check for each record in column1 if the string contains the substring and returns the raws that match(so for that example it will return the raw:
thisisstring1 thisisstring2

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-15 : 04:53:58

where @search_string like '%'+column1+'%'

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-15 : 04:54:15
[code]select * from table where @yourstring like '%' + column1 + '%'

or
select * from table where patindex('%' + column1 + '%',@yourstring)>0
[/code]
Go to Top of Page
   

- Advertisement -