现在需要执列值的更新任务:
根据第N+1行列shou的值决定第N行列ceng的值,数据有100万条。
请问是否需要使用两个游标?使用那种游标,基表、静态、只进、只进/只读、键集驱动型游标,速度相对比较快?
请教!

解决方案 »

  1.   

    假设有cluster keycolumn,
    update a set a.shou=b.shou from tablename a,tablename b where b.keycolumn=(select min(keycolumn) from tablename where keycolumn>a.keycolumn)
    如果没有可以
    alter tablename tablename add sn int identity(1,1)
    go
    update a set a.shou=b.shou from tablename a,tablename b where b.sn=a.sn+1
      

  2.   

    关注这个问题!我也有此疑惑,像excel vba,
    for i=1 to 100   '第1至100行记录
     a=.cells(i,1)   '当前行的A列值
     b=.cells(i+1,1) '下一行的A列值
     if (a,b满足什么条件)下then    更新i行动的B列
    end ifnext i
    这样的思路在SQL server中怎样实现?