如果检查第三列 C2,第四列C2,第五列C4,任意一列都已更新,用语句if(columus_updated()&14) >0
这是他的update_bitmask是14,如果换成第9,8,7列呢?请指教如何计算update_bitmask。

解决方案 »

  1.   

    if update(C9) and update(C8) and update(C7)这样不行吗?
      

  2.   

    IF (SUBSTRING(COLUMNS_UPDATED(),(@i - 1) / 8 + 1, 1)) & POWER(2, (@i - 1) % 8) > 0 
    则@i列受影响
      

  3.   

    columns_update 函数返回值的二进制位对应表的列(假设总共有 16 列)应该是这样
    c8 c7  c6  c5 c4  c3 c2 c1  c16 c15 c14 c13 c12  c11 c10 c9
    0    0   0   0   0   0   0   0     0    0     0     0     0    0    0    0检查 c2、c3、c4 对应的二进制数为 0000 1110 0000 0000 ,十六进制为 0xE00
    columns_update() & 0xE00检查 c7、c8、c9 对应的二进制数为 1100 0000 0000 0001,十进制为 0xC001
    columns_update() & 0xC001
      

  4.   


    猫大侠,顺序为什么是这样:c8 c7 c6 c5 c4 c3 c2 c1 c16 c15 c14 c13 c12 c11 c10 c9
      

  5.   

    100000000=9
    10000000=8
    1000000=7所以有 power(2,6)+power(2,7)+power(2,8)=448所以有 if(columus_updated()&448) >0
      

  6.   


    -- 理论结合实际,完善一下
    if OBJECT_ID('tab') is not null 
     drop table tab;
    go
    create table tab
    (c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,
     c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int);
    go
    create trigger trg_update_tab on tab
    for update
    as
     print columns_updated();
     rollback tran;
    go
    insert into tab values(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
    go
    update tab set c1=0;
    /*0x0100 */
    update tab set c2=0,c3=0,c4=0;
    /*0x0E00 */
    update tab set c7=0,c8=0,c9=0;
    /*0xC001 */