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 2000 Forums
 Transact-SQL (2000)
 comma seperated list

Author  Topic 

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-03-18 : 11:20:46
how do you select from a column/variable that has a comma seperated list in it - returning a row for each item in the comma seperated list

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-18 : 11:30:15
with dynamic sql exec('select ... from ... where id in(' + @YourCSVString + ')')

or by use of CSVtoInt function
http://www.sqlteam.com/item.asp?ItemID=11499

Go with the flow & have fun! Else fight the flow
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2005-03-18 : 11:47:21
That's brilliant thanks!
I changed csvToInt to work as CsvToVarchar
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-03-18 : 11:53:09
or the every confusing:

select ... from...
where ','+@YourCSVString+',' like '%,'+convert(varchar,id)+',%'

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page
   

- Advertisement -