Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Concatenated String
Message
 
 
To
23/09/2013 21:35:16
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01583959
Message ID:
01583961
Views:
62
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform