January 4, 2007 at 8:11 am
What is the best way to show the number of rows that would be affected by an update statement w/o actually performing the update?
I could create a Transaction assign the @@Rowcount Variable to another variable and display it then rollback the transaction like so but I was wondering if there was an better way.
Begin Transaction
Declare @HowMany as int
Update tbla set field1 = 3 where type = 'A'
Set @HowMany = @@rowcount
print @HowMany
Rollback Transaction
January 4, 2007 at 8:20 am
This is really the long and most cumbersome way to do it, and you'll also make your transaction log grow for no use.
Why not just count it?
Declare @HowMany as int
SELECT @HowMany = COUNT(*) FROM tbla WHERE type = 'A'
That is, the best way is to select instead of update with the same criteria, then you'll know how many rows that are going to be affected. (unless something changes between the count and the actual update =;o)
/Kenneth
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply