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 string in a column?

Author  Topic 

nayanancha
Starting Member

27 Posts

Posted - 2012-02-23 : 09:12:19
I have a table with Column name 'Roles' which has 3 roles.

So when I do
Select Roles from Table

I get

Admin
Customer
SalesRep

So I need to check for a string 'Admin' if its there in this column. How can I check this?

Thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-23 : 09:17:51
Select Roles from Table WHERE Roles = 'Admin'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nayanancha
Starting Member

27 Posts

Posted - 2012-02-23 : 09:46:34
I have a string as Roles='Admin,Customer,SalesRep'

So I have a function which takes that string and returns a column with values

Column
------
Admin
Customer
SalesRep

So I need to check for a particular Role 'Admin'

If(Role='Admin' exists in that Column)
Do this

So I need to check that If condition.

Thanks,
Nayan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-23 : 09:55:41
i'm not sure on what your function returns so i guess it will somethig like

SELECT Val FROM dbo.ParseValues('Admin,Customer,SalesRep',',') WHERE Val='Admin'


i've used my function which does similar function

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -