[code="sql"]CREATE TABLE #t (a int);GOCREATE PROCEDURE dotestASUPDATE #t SET a = 1 WHERE 1 = 0;RETURN @@ERROR;GOEXEC dotest;SELECT @@ROWCOUNT;[/code]If you run the above, there is a single result set with a 1 for rowcount. In the messages pane, the display is:(0 row(s) affected)(1 row(s) affected)The zero rows are for the procedure that ran the update and the one row is for the selection of @@ROWCOUNT (if you remove the selection of rowcount, just the zero rows is displayed).I know that @@ROWCOUNT is 1 and not 0 because of the RETURN @@ERROR line. But I am required to have that line in the procedure per code standards.I'm writing T-SQL unit tests in Visual Studio (also a requirement).Obviously the zero rows affected value is available. SQL Server knows that zero rows were updated. However, that information is not in @@ROWCOUNT. Where is it? I need to get it in T-SQL so the test can verify that it's zero. I cannot modify the procedure to make the unit test work. I can change any T-SQL that is not in the procedure itself.Note that the caller of the procedure (in .NET), correctly gets the zero for rows updated. So the production code works, just not the unit test.Does anyone know where to get the message that zero rows were updated in T-SQL?
↧