Empcode Empname COmpany Department Question Scale
-----------------------------------------------------------------------
1001 ABC Comp1 IT Development Opportunities 50
1001 ABC Comp1 IT Goals and Targets Set 30
1001 ABC Comp1 IT Feedback and Coaching 10
1002 XYZ Comp1 IT Goals and Targets Set 60
1002 XYZ Comp1 IT Feedback and Coaching 70
我试过的查询:
DECLARE @cols AS NVARCHAR(MAX)
DECLARE @query AS NVARCHAR(MAX)
SELECT @cols = STUFF((SELECT distinct ',' + QUOTENAME(Question)
from TmpTest1
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT Empcode,Empname,Company,Department,' + @cols + '
from
(
select *
from TmpTest1
) x
pivot
(
max(scale)
for Question in (' + @cols + ')
) p '
execute(@query)
执行后我想返回结果集并继续。我该怎么做?
答案 0 :(得分:0)
如果我理解你的问题,你可以创建一个临时表,并将结果集放到一个临时表中,你可以在返回最终结果之前进行进一步的处理。