TSQL transaction checking both @@ERROR and @@ROWCOUNT after a statement TSQL transaction checking both @@ERROR and @@ROWCOUNT after a statement sql-server sql-server

TSQL transaction checking both @@ERROR and @@ROWCOUNT after a statement


Store both into your own variables in a single query, then check:

DECLARE @rc intDECLARE @err intSELECT @Param1UPDATE [dbo].[Table1]SET    Col2 = 'something'WHERE Col1 = @Param1SELECT @rc = @@ROWCOUNT,@err = @@ERRORIF @err <> 0BEGIN    ROLLBACK TRAN    RETURN -12ENDIF @rc = 0BEGIN    ROLLBACK TRAN    RETURN -27END