做完儲值卡批量存款單審核后,儲值卡庫存出現(xiàn)沒有減庫存的SQL腳本?
-----查詢所有審核的單據(jù)
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,出現(xiàn)問題的時間)<=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
-----上述中是取的是儲值卡批量存取款單的數(shù)據(jù),也可以修改成其他單據(jù),例如銷售單,但是要注意修改對應(yīng)的參數(shù),主要是@c_store_id,在這里取的制單門店的機構(gòu)。