0

Could you please help? I have one column with ID and in another table columne where are few IDs in one row separeted with ','

I need something like simple check whether ID is in column 2 or not ...something like:

Case When
Column1(123) like Column2(123,345,567)
Then 1
Else 0
END

...but this is not working.

pirho
  • 11,565
  • 12
  • 43
  • 70
Viktor
  • 1
  • 3
    Why don't you store it in a relation table in the first place? You should create a second table which links to this table via foreign-key. There you add those three records. Then you can use `Case When EXISTS(SELECT 1 FROM T2 WHERE T2.ID=T1.ID) THEN 1 ELSE 0 END` – Tim Schmelter Oct 13 '14 at 15:03
  • 1
    Keeping IDs in a comma separated list can be a real headache and I'd advise you to perhaps redesign your database to proper standards. [You may find this as a solution to your current problem.](http://stackoverflow.com/a/10914602/1200185) – Alternatex Oct 13 '14 at 15:11
  • Check out my answer here: http://dba.stackexchange.com/questions/72292/splitting-a-csv-column-from-select-query-into-multiple-columns/72298#72298 – Pieter Geerkens Oct 13 '14 at 15:11
  • @Viktor Fix your database design. It's for your sake. – Eric Feb 27 '18 at 21:08

0 Answers0