@@ROWCOUNT IN SQL SERVER 2005

1. @@ROWCOUNT returns the number of rows affected by the last statement.
2. If the number of rows is more than 2 billion, use ROWCOUNT_BIG.
3. Return type of @@ROWCOUNT is int.
4. You can set this @@rowcount to some other variable and use them for further processing.

Examples
______________________________

1. SELECT * FROM employee
PRINT @@rowcount

Output
______________________________

5 —-as there are 5 rows in the table

2.SELECT * FROM employee
PRINT ‘sdfsd’
PRINT @@rowcount

Output
______________________________

0 —-as the last executed statement does not affect any rows.

3.
DECLARE @rows AS INT
SELECT * FROM employee
SET @rows = @@rowcount
PRINT ‘No of Rows’ + SPACE(1) + ‘:’ + SPACE(1) + CAST(@rows AS VARCHAR(2))

Output
______________________________

No of Rows : 5 —-as there are 5 rows in the table

Happy Programming.

Pawan Kumar
pawankkmr@gmail.com