I have the following query;
SELECT custom.name, instance_id
FROM table1 tb
WHERE tb.instance_id = 1111 OR tb.instance_id = 2222
This returns the following results;
test, 1111
test1, 1111
test3, 1111
tabletest, 2222
tabletest1, 2222
tabletest2, 2222
I would like the ability to match the instances_id, and combine the matching rows into a single string.
i.e.
test;test1;test3
tabletest;tabletest1;tabletest2
I can get a single string but at the moment this grabs all the results and puts it into a single string.
STUFF((
SELECT custom.name + ';'
FROM table1 tb
WHERE tb.instance_id = 1111 OR tb.instance_id = 222
FOR XML PATH(' '), TYPE.value('.', 'NVARCHAR(MAX)'), 1, 0, ' ')
this results in
test;test1;test3;tabletest;tabletest1;tabletest2
Unfortunately I cannot upgrade past sql server version 15 which perhaps limits me.