SELECT kp_order_number, kp_codeand_color AS kp_item_code , kp_yltype_name AS '类别' ,kp_item_name as '名称' ,kp_item_size as '规格' ,kp_color as '颜色', kp_unit_no as '单位',kp_waster as '损耗',kp_waster_qty
into #t FROM jb_fw_detail a ,jb_bagyltype b
WHERE (a.kp_type_id=b.kp_yltype_no)
AND kp_sheet_no=@sheetno
--ORDER BY b.kp_order_number
declare @sql varchar(8000)
set @sql = 'select 类别 ,名称 ,规格 ,颜色, 单位,损耗 '
select @sql = @sql + ', sum(case kp_item_code when '''+kp_item_code+''' then kp_waster_qty else 0 end) ['+kp_item_code+'] '
from (
select distinct kp_item_code from #t
) as a
set @sql=@sql+' from #t group by 类别 ,名称 ,规格 ,颜色, 单位,损耗 ,kp_order_number order by kp_order_number '
exec(@sql)
drop table #t
sql 横向显示数据
最新推荐文章于 2024-02-19 10:03:46 发布