What is the correct type for @@ROWCOUNT?

1.8k views Asked by At

I am writing a stored procedure in SQL Server 2008 and I need to count the rows affected by a query.

DECLARE
    @my_rows                    AS INT

and then

SELECT *
FROM a table
WHERE some conditions
SET @my_rows=@@ROWCOUNT

if I declare my_rows as varchar it works correctly but if I declare as INT I get the following error:

Arithmetic overflow error converting expression to data type tinyint.

What is the correct type to declare? I think that the numer of rows could only be integer and betweeb 0 and the total numer of rows.

1

There are 1 answers

3
Harshal Yelpale On BEST ANSWER

As Per MSDN the correct return type of @@ROWCOUNT is int.

SQL code is fine, working properly even @my_rows declared as tinyint.