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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Nightmare on Update Street

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2002-10-29 : 10:38:13
Hey, it's almost Halloween.

I have taken blows from a stored procedure that updates a single user record. I was surprised that no error condition was set when the record was not found.

UPDATE Admins
SET Password = @Password
WHERE AdminID = @AdminID
SET @ERR = @@ERROR

It seems to me that the right way to check that an update actually occured would be to check @@ROWCOUNT, since @ERR is 0, even if a record was not updated.

UN-fortunately, it seems that the SET @ERR statement has set @@ROWCOUNT TO 1.

How can I retrieve both @@ROWCOUNT AND @@ERROR from the UPDATE statement??

Thanks, and Boo!

Sam

nr
SQLTeam MVY

12543 Posts

Posted - 2002-10-29 : 10:42:01
No error is set because there isn't an error. Your where statement has excluded all records which is OK.

to check
UPDATE Admins
SET Password = @Password
WHERE AdminID = @AdminID
select @ERR = @@ERROR, @rowcount = @@rowcount
if @ERR <> 0 or @rowcount = 0
begin


end


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2002-10-29 : 11:04:46
Thank you Nigel !

Sam

Go to Top of Page
   

- Advertisement -