上面的有乱吗,重发一次,谢谢大家,给看一下
--库存查询(含订订单)
CREATE  PROCEDURE dt_inv_jskc_new_ls
@ckdm varchar(20),
@wldm varchar(20),
@rq varchar(20)
 AS
--gaowen
select code,zdkc as jc,zdkc as jc1  into #lsb from inv_zl_wlxx where 1<>1
insert into #lsb(code,jc) select wlbh,jcsl from inv_kc_jskc where ckbh like @ckdm+'%' and wlbh like @wldm+'%' and ckbh in (select bmdm from inv_zl_ckxx where jhys=1 ) select dm into #ckd from  inv_cz_ckd where ckdm like @ckdm+'%' and zt<>20  and ckdm in (select bmdm from inv_zl_ckxx where jhys=1 )  and rq<=@rq
select dm into #rkd from  inv_cz_rkd where ckdm like @ckdm+'%' and zt<>20  and ckdm in (select bmdm from inv_zl_ckxx where jhys=1) and rq<=@rq
select dm into #dbdzr  from  inv_db_dbd where zrhw like @ckdm+'%' and zt<>20  and zrhw in (select bmdm from inv_zl_ckxx where jhys=1 ) and rq<=@rq
select dm into #dbdzc  from  inv_db_dbd where zchw like @ckdm+'%' and zt<>20  and zchw in (select bmdm from inv_zl_ckxx where jhys=1 ) and rq<=@rqinsert into #lsb(code,jc) select wldm,sl from inv_cz_rkd_detail where dm in(select dm from #rkd) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl*( - 1 ) from inv_cz_ckd_detail where dm in(select dm from #ckd) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl  from inv_db_dbd_detail where dm in(select dm from #dbdzr) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl*( - 1)  from inv_db_dbd_detail where dm in(select dm from #dbdzc) and wldm like @wldm+'%'insert into #lsb(code,jc) select wldm,( - 1)*sl from inv_cz_rkd_detail where dm in(select dm from  inv_cz_ckd where rq>@rq and ckdm like @ckdm+'%' and zt=20  and ckdm in (select bmdm from inv_zl_ckxx where jhys=1 ) ) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl from inv_cz_ckd_detail where dm in (select dm    from  inv_cz_rkd where rq>@rq and ckdm like @ckdm+'%' and zt=20  and ckdm in (select bmdm from inv_zl_ckxx where jhys=1)) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl*( - 1)   from inv_db_dbd_detail where dm in(select dm  from  inv_db_dbd where rq>@rq and zrhw like @ckdm+'%' and zt=20  and zrhw in (select bmdm from inv_zl_ckxx where jhys=1 )) and wldm like @wldm+'%'
insert into #lsb(code,jc) select wldm,sl   from inv_db_dbd_detail where dm in(select dm    from  inv_db_dbd where rq>@rq and  zchw like @ckdm+'%' and zt=20  and zchw in (select bmdm from inv_zl_ckxx where jhys=1 )) and wldm like @wldm+'%'select code,sum(jc) as jc,sum(jc) as jc1 into #lsb1 from #lsb  group by code order by code
update #lsb1 set jc1=0
update #lsb1 set jc1=(select sum(sl) from sdm_dd_xsd_detail where dm in (select dm from sdm_dd_xsd where qx=0 and jq=0 ) and wldm=#lsb1.code)delete from #lsb1 where code in (select code from inv_zl_wlxx where wllx='05' or wllx='06')select a.code as 物料代码,b.mc as 物料名称,b.wlgg as 规格,b.jldwmc as 单位, a.jc as 结存,a.jc1 as 订单,c.mc as 类别  from #lsb1 a inner join inv_zl_wlxx b on a.code=b.code left outer join sys_jcxxb c on c.code=b.ly  where jc<>0 order by a.code
GO