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)
 passing comma seperated value

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-04-28 : 16:09:42
I need to search a field that has comma seperated values. So I am passing in a seperated values "1,3,6" and I need to search a comma seperated field. How do I do that?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-04-28 : 16:18:40
use like.

where youCSVColumn like '%' + @yourinputVariable + '%'

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-04-28 : 16:35:26
But what happens if you have a 1,12 and search for a 1. Don't you get both.



quote:
Originally posted by spirit1

use like.

where youCSVColumn like '%' + @yourinputVariable + '%'

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-04-28 : 17:33:40
ok first of all:
This is not a normalized database. It should be.

you can use:
select @yourinputVariable = '%,' +@yourinputVariable + ',%'
select ...
from ...
where ',' + yourCSVColumn + ',' like @yourinputVariable

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-04-29 : 12:41:38
See also: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CSV,Splitting%20delimited%20lists,Best%20split%20functions

Kristen
Go to Top of Page
   

- Advertisement -