I have a stored procedure which deletes certain records. I need to get the number of deleted records.
I tried to do it like this:
DELETE FROM OperationsV1.dbo.Files WHERE FileID = @FileID
SELECT @@ROWCOUNT AS DELETED;
But DELETED is shown as 0, though the appropriate records are deleted. I tried SET NOCOUNT OFF; without success. Could you please help?
Thanks.
That should work fine. The setting of
NOCOUNTis irrelevant. This only affects then rows affectedinformation sent back to the client and has no effect on the workings of@@ROWCOUNT.Do you have any statements between the two that you have shown?
@@ROWCOUNTis reset after every statement so you must retrieve the value immediately with no intervening statements.