Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doing IN backwards.... 1

Status
Not open for further replies.

nohandlesleft254

IS-IT--Management
Apr 19, 2006
58
GB
Hi,

I have a column in a table that is a string (ALL,ACCE,PB,CORN). When i query this table i need to be able to look in this string for my var (say PB). 'LIKE' with wildcards works most of the time but i do have some lists like ALL,ACCE,PBS,CORN, so it obviously returns both. How can i say find 'MyVar'(as a whole list element) in 'ListField'?

Thanks
 
For comparison purposes, put a comma at the beginning of the string and the end, and then include the commas in the like pattern. Like this...

Code:
Declare @Temp Table(Data VarChar(100))

Insert Into @Temp Values('ALL,ACCE,PBS,CORN,')
Insert Into @Temp Values('ALL,ACCE,PB,CORN,')

Select Data
From   @Temp
Where  ',' + Data + ',' Like '%,PB,%'

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top