我有一个动态的pivot sql脚本(透视列是动态的)。我想将结果集导出到excel文件中并通过发送邮件任务在ssis中通过电子邮件发送。有谁知道这是怎么做到的吗?下面是我的动态列透视sql脚本
Declare @SQL varchar(max)
Select @SQL = Stuff((Select Distinct ',' + QuoteName([Response Code]) From YourTable Order by 1 For XML Path('')),1,1,'')
Select @SQL = 'Select [Employee],' + @SQL + '
From (
Select [Employee],[Response Code],Cnt=1,Lvl=0 from YourTable
Union All
Select [Employee],[Response Code],Cnt=0,Lvl=0 from (Select Distinct [Employee] from YourTable) A Join (Select Distinct [Response Code] from YourTable) B on 1=1
Union All
Select ''Total'',[Response Code],count(*),1 From YourTable Group By [Response Code]
) A
Pivot (sum(Cnt) For [Response Code] in (' + @SQL + ') ) p'
Exec(@SQL);
上面的脚本会像这样返回表格
Employee ptb ulm vml wrn
Emp A 0 0 2 1
Emp B 0 2 0 1
Emp C 1 0 1 0
Total 1 2 3 2
我需要将上面的结果表导出到excel文件中。我知道如果列是静态的,如何使用SSIS;但我正在努力使用动态列枢轴。有谁可以帮助我。非常感谢你的时间和帮助