請問如下CheckSum()應用有沒有問題 Insert Into dbo.TA_STOGoodsBalance(STO_001,STO_002,STO_003,STO_004)
Select INT_003, INT_004, ltrim(rtrim(INT_005)) ,SUM(isnull(INT_006,0))
From Inserted
Where CheckSUM(INT_003,INT_004,ltrim(rtrim(INT_005)) ) NOT IN
(Select CheckSUM( STO_001, STO_002,ltrim(rtrim(STO_003)))
From dbo.TA_STOGoodsBalance )
Group by INT_003, INT_004,ltrim(rtrim(INT_005))
Select INT_003, INT_004, ltrim(rtrim(INT_005)) ,SUM(isnull(INT_006,0))
From Inserted
Where CheckSUM(INT_003,INT_004,ltrim(rtrim(INT_005)) ) NOT IN
(Select CheckSUM( STO_001, STO_002,ltrim(rtrim(STO_003)))
From dbo.TA_STOGoodsBalance )
Group by INT_003, INT_004,ltrim(rtrim(INT_005))
这样的checksum应该还不是完全保险
应该使用join tb on f1=fb and f2=fb
但是,不相同的内容,hash也可能正好一样,虽然概率很小
Select a.INT_003, a.INT_004, ltrim(rtrim(a.INT_005)) ,SUM(isnull(a.INT_006,0))
From Inserted a
left join dbo.TA_STOGoodsBalance b
on a.INT_003=b.STO_001
and a.INT_004=b.STO_002
and ltrim(rtrim(a.INT_005)=ltrim(rtrim(b.STO_003)
Where b.STO_001 is null
Group by a.INT_003, a.INT_004,ltrim(rtrim(a.INT_005))
尚不支持 (f1,f2,f3) in (select fa,fb,fc from b ... )
替换方式为:left join b on a.f1=b.fa and a.f2=b.fb and a.f3=b.fc ... where b.fa is not null and b.fb is not null and b.fc is not null