做完储值卡批量存款单审核后,储值卡库存出现没有减库存的SQL脚本?
-----查询所有审核的单据
select row_number() over(order by a.c_id) as c_sort , a.c_id,a.c_mk_store_id,a.c_au_userno,b.c_st_cardno,b.c_en_cardno
into #card
from tb_o_d_batch a (nolock) inner join tb_o_d_batchg b(Nolock) on a.c_id=b.c_id
where DATEDIFF(day,a.c_au_dt,出现问题的时间)<=0
and a.c_status='已审核'
----更新所有卡的库存
declare @count int
select @count=1
declare @zcount int
select @zcount=COUNT(*) from #card
select @zcount
while @count<=@zcount
begin
declare @c_id varchar(30), @c_store_id varchar(10),@c_au_userno varchar(10),@c_st_cardno varchar(30),@c_en_cardno varchar(30)
select @c_id=c_id,@c_store_id=c_mk_store_id,@c_au_userno=c_au_userno,@c_st_cardno=c_st_cardno,@c_en_cardno=c_en_cardno from #card
where c_sort=@count
execute up_set_cardcount 'out' , @c_store_id , @c_au_userno , @c_id,@c_st_cardno,@c_en_cardno , @c_st_cardno , @c_en_cardno ,'销售'
select @count=@count+1
end
-----上述中是取的是储值卡批量存取款单的数据,也可以修改成其他单据,例如销售单,但是要注意修改对应的参数,主要是@c_store_id,在这里取的制单门店的机构。