执行不成功不一定产生error
产生错误@@error才是<>0

解决方案 »

  1.   

    @@rowcount;任何不返回行的语句将这一变量设置为 0
    所以@@rowcount一定紧跟在SQL下用改一下你的代码:
    declare @row int
    set nocount on
    begin tran
    update onhope set num=num-1,finish_da=case
                                            when num=1 then getdate()
                                            else null
                                            end    
    where operator='CRX' and on_ref='138642SHA' AND SIZE='40'
      AND NUM>0set @row=@@rowcountif @@error<>0
      goto on_errorif @row=0
      begin
      print 'rowcount'
      end
    commit tran
    returnon_error:
      rollback tran
      

  2.   

    你的也有问题@@error始终为0,因set @row=@@rowcount始终正确,是否应select @row=@@rowcount,@error=@@error
      

  3.   

    dull_knife(钝_刀) 说的对
    declare @row int
    declare @error int
    set nocount on
    begin tran
    update onhope set num=num-1,finish_da=case
                                            when num=1 then getdate()
                                            else null
                                            end    
    where operator='CRX' and on_ref='138642SHA' AND SIZE='40'
      AND NUM>0select @row=@@rowcount,@error=@@error if @error<>0
      goto on_errorif @row=0
      begin
      print 'rowcount'
      end
    commit tran
    returnon_error:
      rollback tran