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 2008 Forums
 Transact-SQL (2008)
 How to check for a particular word from a string??

Author  Topic 

nayanancha
Starting Member

27 Posts

Posted - 2012-02-22 : 11:57:26
I need to see whether a particular word is there in a string or not.

Like @Roles = 'Admin,Customer'

I need to check whether 'Admin' word is there in @Roles. How can I do this?

Thanks,

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-02-22 : 12:25:09
You can use the like construct:
SELECT CASE WHEN ','+@roles+',' LIKE '%,Admin,%' THEN 'Yes' ELSE 'No' END;
Go to Top of Page
   

- Advertisement -