>I need to concatenate multiple email addresses into one string separated by carriage return and line feed. The table I'm dealing with can have multiple email address records for each parent record. I'm assuming I'll need to loop through the email address table and build the string but I'm not quite sure how to do this in a SQL Scalar-Valued function. Any one have an example you could point me to?
>
>TIA
>Jeff
You may want to use XML PATH approach for string concatenation, e.g.
select P.*, stuff((select char(13)+char(10) + E.Email from Emails E where E.PersonID = P.PersonID
order by CreationDate FOR XML PATH(''), type).value('.', 'varchar(max)'), 2, '') as Emails
FROM dbo.Personell P order by P.LastName, P.FirstName
Take a look at
http://social.technet.microsoft.com/wiki/contents/articles/19670.t-sql-useful-links.aspx#Concatenate_Rows
If it's not broken, fix it until it is.
My Blog