Adding different values ​​from one column to each other

I wrote one Windows service that sends an email depending on the entries in the table. This service selects pending emails from the table, sends them to the specified email address.

The attributes of my table are Sender, Receiver, Subject, Body.

I can get all the records from the table by following the write procedure. But in most cases, in this table there are records with the same subject, sender and recipient, but with a different body.

So, I just want to add the body of letters with the same subject. Instead of sending more than one email, the body of the entire email will be added, and I can only send one email address if Subject matches.

Or what if I do this from my C # Windows service code?

Please help me.

+3
source share
1 answer

Thanks for your reply. I was able to do this with the following query:

SELECT [Subject], STUFF((SELECT ', ' + [Body] FROM CCSEmails T2 WHERE T1.[Subject] = T2.[Subject] Order By [Body] FOR XML PATH('')),1,1,'') AS [Body] FROM CCSEmails T1 GROUP BY [Subject] 
+1
source

All Articles