I have a table with a column containing values in a comma-separated list, like so:
| ObjectID (int) | Column1 (nvarchar(max))|
| 1 | 152, 154, 157, 158 |
| 2 | 101, 154, 155 |
| 3 | 97, 98, 99 |
I need to select all the ObjectIDs that have Column1 with ALL the integer values found in a particular string: '155, 154'. That way, only row with ObjectID = 2 should be returned, as it contains both 155 and 154 integers in its Column1 string.
I was trying something like this:
DECLARE @SearchString nvarchar(max) = '155,154';
SELECT *
FROM ObjectsTable
WHERE EXISTS
(SELECT Data FROM dbo.SplitString(Column1, ',')
WHERE Data = ALL (SELECT Data FROM dbo.SplitString(@SearchString, ',')))
But unfortunately, it does not return any records for me. Any idea how I can handle this, if it's even possible?