在sql server里有这么一段语句,
declare @sql varchar(8000)
set @sql = ''
select @sql = @sql +
',sum(case when sp_size='''+CAST(sp_size as varchar)+''' then remain_num else 0 end) as [' +
CAST(sp_size as varchar)+']'
from storage
group by sp_size
select @sql = 'select sp_name,sp_dw,price' + @sql + ',sum(remain_num) as 小计 from storage group by sp_name,sp_dw,price'
exec(@sql)
然后delphi窗体中ADOQuery 如何获取结果集或者获取@sql值或者生成一个临时表能读也可以。
------解决方案--------------------
调用存储过程:
declare @t varchar(8000)
exec proc_ttt @t out