修改语句后加个判断
if @@error <> 0
begin
      update --- set col1 = 'error'--where ----
end默认就是发生错误也会往下执行(17以下的错误),发生比较严重的错误如资源错误的话怎末控制也不可能往下执行

解决方案 »

  1.   

    我是这个意思:
         
            if @@error <> 0  
    begin
    update tdble set count= num
    end
    如果num列都是数字,自然没有问题,但是num是个字符型的字段,数值可能是123的数字,也可能是a1 a2这样的字符。这里要求的是 是123 就更新为123 不时地化,填入0 我估计应该用 case ,不知有何高招
      

  2.   

    if @@error <> 0  
    begin
    update tdble set count= case when isnumeric(num)=1 then num else 0 end
    end
      

  3.   

    所有的T-SQL语句自行完毕后都会得到诸如@@error ,@@rowcount等全局函数,你只需判断他们的值即可!
      

  4.   

    谢谢各位。 上面的例子是一个随便的例子,主要的问题就在于很多情况下字符比较复杂,远远不是一个  isnumeric 可以搞定的,我想知道update tdble set count= case when isnumeric(num)=1 then num else 0 end  中的 else 0的位置上,能否进行@error的判断。例如,能不能写成 else 0  --->   else  case  @@error when 0 then 1 else 0 这样把@error 引入到循环控制中来。