34,587
社区成员
发帖
与我相关
我的任务
分享
declare @tb1 table(DAH int, LSQF decimal(5,2))
insert @tb1 select
2 , 2.00 union all select
3 , 24.00 union all select
4 , 5.00 union all select
5 , 6.00 union all select
6 , 8.00
declare @tb2 table(DAH int, YCYE decimal(5,2))
insert @tb2 select
2, 3.00 union all select
3 , 4.00 union all select
4 , 55.00 union all select
5 , 63.00 union all select
6 , 2.00
select a.* into #t from @tb1 a,@tb2 b where a.dah=b.dah and ycye>lsqf
update @tb2 set YCYE=ycye-lsqf
from @tb2 b,#t a where a.dah=b.dah
delete from @tb1 where dah in (select dah from #t)
----------TB2的YCYE的数值比TB1的LSQF大 -------------------
select a.dah,a.lsqf,b.ycye into #t1 from @tb1 a,@tb2 b where a.dah=b.dah and ycye<lsqf
update @tb1 set lsqf=b.ycye-b.lsqf from @tb1 a,#t1 b where a.dah=b.dah
update @tb2 set ycye=b.ycye-b.lsqf from @tb2 a,#t1 b where a.dah=b.dah
----------TB2的YCYE的数值比TB1的LSQF小--------------------
select * from @tb2
DAH YCYE
----------- ---------------------------------------
2 1.00
3 -20.00
4 50.00
5 57.00
6 -6.00
(5 行受影响)
select * from @tb1
DAH LSQF
----------- ---------------------------------------
3 -20.00
6 -6.00
(2 行受影响)
drop table #t
drop table #t1