What is the scope of @@rowcount ?MSDN doesn\'t mention its scope.
Returns the number of rows affected by the last statement.
every insert/update/select/set/delete statement resets the @@rowcount to the rows affected by the executed statement
begin
declare @myrowcount int,
@myrowcount2 int
insert stmt
SET @myrowcount=@@rowcount
if @myrowcount>0
begin
insert stmt
SET @myrowcount2 =@@rowcount
if @myrowcount2 >0
do smthg
end
end
or try this
SELECT * FROM master.sys.objects -- 50 rows
IF (1=1)
SELECT @@ROWCOUNT AS RowsAffected -- 0, because the IF did not affect any rows
even an IF statement affects it....hence its scope is the last statement read.