Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Concatenated String
Message
 
 
À
23/09/2013 21:35:16
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01583959
Message ID:
01583961
Vues:
61
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform