日期:2014-05-17 浏览次数:20604 次
update set a.xx=t.xx... from 你要更新的表 a inner join #t b on a.主键=b.主键
------解决方案--------------------
先给b 行列转换一下 然后在join 一下更新
;WITH t AS ( SELECT aid , [c.name] AS [name] , [c.sex] AS [sex] FROM ( SELECT [aid] , [fieldname] , [value] FROM [tb] ) a PIVOT ( MAX([value]) FOR [fieldname] IN ([c.name] , [c.sex]) ) pvt ) UPDATE c SET c.name=t.[name] , c.sex=t.[sex] FROM c ,t WHERE c.aid = b.aid