有什么办法给数据集汇总
如exec(@SelectResult) --这里面的列的个数是不固定的,有是会3列,有时会四列.列的个数是未知.如exec(@SelectResult)这时的结果是这样1 4.5 62 2.1 3我想把上面的数据汇总一下.结果为1 4.5 62 2.1 33 6.6 9
create table t( id int, num int)insert into tselect 1,5 union allselect 2,6declare @tab table( id int, num int)insert into @tabselect * from t union allselect SUM(ID),SUM(num) from tselect * 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'