Lot of newbies struggle to unserstand how @@Rowcount works in SQL Server. @@Rowcount is used to know the number of rows affected for the last select,insert,update or delete statements. You should use @@rowcount immediately after the statement
For example the following returns 1 row
select 100
To get row count, use @@rowcount immediately after the statemnet
select 100
select @@rowcount
It returns the values 100 and 1
Don't make any checkings directly on @@rowcount and assign it's value to a variable.
declare @row int
select 100
if @@rowcount>1
set @row=@@rowcount
--do some stuff
The above will return 0 becuase as soon as if @@rowcount>0 is executed it is reset to 0 as it doesn't return any rows. So always assign to variable first
declare @row int
select 100
set @row=@@rowcount
if @row>0
--do some stuff