Alex
Alex

Reputation: 36101

Find amount of updated rows in T-SQL

I need to find the amount of updated rows

UPDATE Table SET value=2 WHERE value2=1

declare @aaa int
set @aaa = @@ROWCOUNT

It doesn't work. How can I do that?

Upvotes: 1

Views: 911

Answers (1)

DVK
DVK

Reputation: 129383

  1. You may want to declare before you do the update. I am not sure but declare statement might affect @@rowcount.

  2. You are not getting the @aaa value back - you want to select it out if you want to see it outside the query

.

declare @aaa int -- this name's noty the best... use @row_count instead ;)
UPDATE Table SET value=2 WHERE value2=1
set @aaa = @@ROWCOUNT
select @aaa

Upvotes: 3

Related Questions