日期:2014-05-18 浏览次数:20572 次
如exec(@SelectResult) --这里面的列的个数是不固定的,有是会3列,有时会四列.列的个数是未知. 如exec(@SelectResult)这时的结果是这样 1 4.5 6 2 2.1 3 我想把上面的数据汇总一下. 结果为 1 4.5 6 2 2.1 3 3 6.6 9
create table t ( id int, num int ) insert into t select 1,5 union all select 2,6 declare @tab table ( id int, num int ) insert into @tab select * from t union all select SUM(ID),SUM(num) from t select * from @tab --drop table t
------解决方案--------------------
set @SelectResult='select a,'+@auto+',c from tb union all select max(a)+1,sum(' +REPLACE(@auto,',','),sum(')+'),max(c) from tb'