用友通整理现场量语句
来源:原创 发布时间:2017-03-22 15:40:03
用通自带整理现存量不行,可以试试下面的整理现场量语句,记得备份数据
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