Hi!
I need some help how to compare values from a table with a csv string.
1. I have a SP that takes a CSV string.
2. I need to check so the values from a SELECT in the SP exists in the CSV string
The problem is that some values in the table must exists in the csv string but there are also values that are grouped, and just one of theses values needs to be found in the csv string.
EX:
CSV string
'foo1', 'foo2', foo3', 'foo5'
SELECT Query in SP will return
C1_Value C2_Group
foo1 1
foo2 2
foo3 3
foo4 3
foo5 4
foo3 and foo4 are in the same group => OR between these values
SQL SP should verify:
is table value 'foo1' in csv string AND
is table value 'foo2' in csv string AND
is table value ('foo3' OR 'foo4') in csv string AND
is table value 'foo5' in csv string
if true return 1 if false return 0
Any tips?
crazy idea:
select distinct C2_Group from Table
left outer join
(
select
C2_Group
from Table
group by C2_Group
having charindex(C1_Value, CSV_STRING) > 0
) as groups
on groups.C2_Group = Table.C2_Group
where groups.C2_Group is null
Or something like that. Sorry if syntax is not exact. Just guessing here.
If the result set is empty then all groups should be represented. If it has results, then those are the ones that do not have a match.
Again, this is more as a idea generator as opposed to a full solution.