应用实例记录
/*一、先求库存数量变化的三种情况*/
select wzid,storageid as st1,storageid2 as st2,
sum(case when inoutflag=2 then amount else 0 end) as 入库,
sum(case when inoutflag=4 then amount else 0 end) as 出库,
sum(case when inoutflag=6 then amount else 0 end) as 调拨出库
from viewinoutall where 1=1 group by wzid,storageid,storageid2 order by wzid,storageid,storageid2
/*二、后求变化的一种情况*/
select * from (
select top 100 percent wzid,storageid2 as st,storageid as st2,
sum(case when inoutflag=6 then amount else 0 end) as 调拨入库
from viewinoutall where 1=1 group by wzid,storageid2,storageid order by wzid,storageid2,storageid
) as aaa where st is not null
/*三、合并(略)*/
附图