if object_id(N'[tempdb].[dbo].[#tempTable]') is not null
drop table #tempTable
go
select A.sName, A.sSerialNO into #tempTable from
(SELECT ClientInfo.sName,BasicInfo.sSerialNO
FROM BasicInfo left join ClientInfo on BasicInfo.nClientID=ClientInfo.nID
where sTechStaff='某某')A
select distinct A.sName,
stuff((SELECT ','+sSerialNO FROM #tempTable WHERE sName=A.sName FOR xml path('')),1,1,'') AS BODY
from
#tempTable A
drop table #tempTable
参考:http://www.cnblogs.com/yuananyun/archive/2010/12/23/1914811.html