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.
| Author |
Topic |
|
Phibian
Starting Member
32 Posts |
Posted - 2005-05-26 : 17:22:14
|
| I have a column in my database in which I'm storing comma separated values (as text).A situation has come up where by it would be nice to compare a number to the comma separated values.I was hoping to do something like SELECT * FROM Table WHERE ValueInt in Table.CSVTextThis obviously doesn't work. Ideas? |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2005-05-26 : 17:26:55
|
| So has anyone suggested not storing CSV's in your database? You might consider normalizing that table.That said ... We've got a number of articles on CSV. You can search the site for those.If you just want to check for a single number that's pretty easy.SELECT CHARINDEX(',19,', ',' + REPLACE(c1, ' ', '') +',') should return all the rows with 19 in the CSV. (The syntax may be a little off).Basically clean out the spaces and add a comma to both ends. Then each number has a delimiter and it pretty easy to search.===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
Phibian
Starting Member
32 Posts |
Posted - 2005-05-26 : 17:44:49
|
| The idea behind storing the CSV was to avoid yet another association table. No reason why we couldn't normalize it. Sigh ;)Thanks for the other idea too though. |
 |
|
|
|
|
|