Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Ken Blum
Constraint Violating Yak Guru
383 Posts |
Posted - 2004-04-21 : 14:25:25
|
| In a SPROC I want to get both @@ROWCOUNT and @@ERROR into variables after an update or insert statement. It seems that once one is set the other is cleared. How can I save them both?Declare @ERVal int, @RCVal intUPDATE MyTable Set MyField = 'Ken' SET @ERVal = @@ERRORSET @RCVal = @@ROWCOUNTRCVal result is 1, even though 21 records are affected. This is due to the previous SET @ERVal command. If I swap them, then I don't get the error if there was one on the UPDATE command because the SET @RCVal command would reset @@ERROR to 0.The ending result is I would like to report both the error code and rowcount when/if there is an error. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-04-21 : 14:26:06
|
| SELECT @ERVal = @@ERROR, @RCVal = @@ROWCOUNTSo you can't do it with SET, but you can with SELECT.Tara |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Ken Blum
Constraint Violating Yak Guru
383 Posts |
Posted - 2004-04-21 : 14:52:40
|
DOH! Thanks kids. |
 |
|
|
|
|
|