日期:2014-05-17 浏览次数:20445 次
create table #t
(供应商 varchar(6),型号 varchar(6), 规格 varchar(6),
[9-1_in] int, [9-1_out] int, [9-2_in] int, [9-2_out] int)
insert into #t
select 'a1', 'x1', '箱', null,10,null,null union all
select 'a1', 'x1', '箱', 5,2,null,20 union all
select 'a2', 'y1', '捆', null,null,8,null union all
select 'a2', 'y1', '捆', 15,null,null,null
declare @tsql varchar(6000)
select @tsql='select 供应商,型号,规格,'
+stuff(
(select ',sum(case when ['+b.name+'] is not null then ['+b.name+'] else 0 end) '''+b.name+''' '
from&nb