Using @@rowcount is nice at times to get the number of rows affected by the last SQL statement. However sometimes you get an unexpected result.
One such situation is with the print statement which is often used as debugging statement in a query.
If looking at the SQL statement:
SELECT 1
UNION
SELECT 2
SELECT @@ROWCOUNT
Then the @@rowcount naturally will return the value 2.
However if we insert a print statement just before the rowcount like this:
SELECT 1
UNION
SELECT 2
PRINT ‘test’
SELECT @@ROWCOUNT
Rowcount now suddenly is 0.
That means the print statement changes the rowcount despite it being just a print to the console window.
Something to be aware of if relying on @@rowcount.