請問如下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))

解决方案 »

  1.   

    一直不太懂CHECKSUM, 搬凳子学习!
      

  2.   

    想实现 (f1,f2) in (select fa,fb from tb ...)?
    这样的checksum应该还不是完全保险
    应该使用join tb on f1=fb and f2=fb
      

  3.   

    checksum()生成的是一个哈希索引,功能类似MD5编码,但是,checksum()是不保证所有不同字段所生成的索引都是相同的,所以,LZ的做法不够严密
      

  4.   

    CHECKSUM()是返回HASH值,如果全部相同,HASH值会相同
      

  5.   


    但是,不相同的内容,hash也可能正好一样,虽然概率很小
      

  6.   

    有沒有可能不能的組合值得到相同的CheckSum值呢?
      

  7.   

    化not in为left join:Insert Into dbo.TA_STOGoodsBalance(STO_001,STO_002,STO_003,STO_004)
    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))
      

  8.   

    避免了checksum的运算,肯定效率高了关键是这种机制是对目前sql语法尚不支持的多列(元组)in的替换实现目前sql语法只支持 f1 in (select fa from b ... )
    尚不支持 (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