I have a table with such a structure, in SQL Server 2012 (simplified for exhibit):
Id | Val
----+----------
1 | 1, 2
2 | 1, 3
3 | 1
4 | 2, 3, 4
I have a stored procedure with a @valIds
list which contains all the Val
I'd like to request, for example 2, 3
or 3
.
In the first case, I'd like lines 1, 2 and 4 to be returned because they contains 2 or 3.
In the second case, I'd like lines 2 and 4 to be returned because they contains 3
Here is a fiddle to reproduce the structure : http://sqlfiddle.com/#!18/ff399/2
I can't figure out how to split the Val
field to search into it and get the above results. Can anyone help me ?
Please note : Spearator is Comma-Space, not just Comma, I'm not sure STRING_SPLIT
can be used here
Thank you