if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([ID] nvarchar(10),[Name] nvarchar(10))
Insert #T
select N'c',N'xx' union all
select N'b',N'xy' union all
select N'b',N'xt' union all
select N'a',N'xe'
Create table #D([ID] nvarchar(10),[Name] nvarchar(10))
Insert #D
select N'a',N'' union all
select N'b',N''
Go
update #D set #D.name=
(SELECT stuff((SELECT ',' + ISNULL([Name], '')
FROM #T t
WHERE ID = #T.ID FOR xml path('')), 1, 1, '') AS Times
FROM #T where #T.id=#D.id
GROUP BY ID)
select * from #T
select * from #D
追问讲讲思路?这个对实际几十万数据可行吗?
追答讲讲思路? 这么清晰的条理....几百万都行,时间长短而已
追问初学的。还有好多要学的。问一下,现在学C#,.net,sql怎么样。