Microsoft SQL Server 2005 Best Practices

How to concatenate all the last names with xml path?

 

Execute the following script in Query Editor to concatenate the last names of AdventureWorks employees:

USE AdventureWorks;

select [Concatenated Last Names ]=
replace(replace((
select distinct LastName as [AllLastNames]
from Person.Contact c
join HumanResources.Employee e
on e.ContactID = c.ContactID
for xml path('')),
'<AllLastNames>', ''),'</AllLastNames>','')

GO


 

The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page