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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-11 : 08:05:11
|
| Florent writes "Hi all,I have a problem with a database that i can't redraw.I have a coma-separated list of Ids in a column, and i have to find in this column a certain Id, let's take "2" for exemple.I've tried : WHERE col_id LIKE '%my_id%';but in this case the query returns 2, 12, 20, 22, etc.I've tried : WHERE col_id LIKE '%,my_id,%';but in this case the query doesn't return the lines where there is only "2" in the comumn, because there is no coma.I thought i could use sub-query, but i can't find there right one...Can somebody help me ?Thanks a lotFlorent" |
|
|
dsdeming
479 Posts |
Posted - 2004-11-11 : 08:19:19
|
| How about WHERE CHARINDEX( ',2,', ',' + col_id + ',' ) > 0. Note that this assumes no spaces following the commas.Dennis |
 |
|
|
|
|
|
|
|