I have the following two tables;
Index Table
ID Index Value
222 Email
222 Phone
222 Customer
333 SMS
333 E Mail,
333 Advisor
Export Table
--------
ID Action Action Time
123 Complete 30/07/2024 10:34
222 Export 30/07/2024 10:34
333 Export 30/07/2024 10:34
444 Complete 30/07/2024 10:34
If I SELECT Index Value FROM Index Table when action is export , I get this result:
select
distinct
stuff((
select ','+ '"'+Index Value+'"'
from [Index] I
inner join Export E on I.ID = E.ID
where E.ID in('222,333')
and E. Action='Export'
for xml path('') ),1,1,'')
I get this:
Email, SMS, Phone, Email, Customer, Advisor
but what I really need is one row with all the values separated by comma as one record and break line at the end and having second record below, like this:
Email, Phone, Customer
SMS, Email, Advisor
New contributor
Tamara Lancaster is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.