用友通整理現(xiàn)場量語句
來源:原創(chuàng) 發(fā)布時(shí)間:2017-03-22 15:40:03
用通自帶整理現(xiàn)存量不行,可以試試下面的整理現(xiàn)場量語句,記得備份數(shù)據(jù)
if exists (select * from tempdb..sysobjects where type=\'u\' and name=\'forcurrentsyz\')
drop table tempdb..forcurrentsyz
go
select cwhcode,cinvcode,sum(iquantity) as iquantity into tempdb..forcurrentsyz from (
select cwhcode,cinvcode,iaInquantity as iquantity from ia_subsidiary where cvoutype=\'34\'
union all
select cwhcode,cinvcode,( case when brdflag=1 then iquantity else -1*(iquantity) end) as iquantity
from rdrecord left join rdrecords on rdrecord.id=rdrecords.id ) a
group by cwhcode,cinvcode
go
delete from currentstock
Go
insert into currentstock (cwhcode,cinvcode,iquantity) select cwhcode,cinvcode,iquantity from tempdb..forcurrentsyz
go