|( You are using SQL2005, right? )
;WITH RecipientsByMail (MailId, RecipientList) AS (
select mx.Id AS MailId ,
( select AddressTable.Name+','
join RecipientTable on RecipientTable.MailTableId = MailTable.Id
join AddressTable on AddressTable.Id = RecipientTable.AddressTableId
WHERE MailTable.Id = mx.Id
FOR XML PATH('')
) AS RecipientList
from MailTable as mx
select m.Id, m.Created, m.Subject, sender.Name, r.RecipientList
from MailTable as m
join SenderTable as s on s.MailTableId = m.Id
join AddressTable as sender on sender.Id = s.AddressTableId
join RecipientsByMail as r on r.MailId = m.Id ;
Please... SAVE my time by rating the posts that you read!
There are 10 kinds of people in the world: those who understand binary and those who don't.