IT:AD:SQL Server:HowTo:SQL:How to use @@ROWCOUNT

Summary

Returns the number of rows affected by the last statement.

Useful in stored procs to branch.

USE AdventureWorks2012;
GO
UPDATE HumanResources.Employee 
SET JobTitle = N'Executive'
WHERE NationalIDNumber = 123456789
IF @@ROWCOUNT = 0
PRINT 'Warning: No rows were updated';
GO

  • /home/skysigal/public_html/data/pages/it/ad/sql_server/howto/sql/how_to_use_rowcount.txt
  • Last modified: 2023/11/04 02:28
  • by 127.0.0.1