@@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
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
所以@@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
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