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)
 exception handling questions

Author  Topic 

shmecher
Starting Member

10 Posts

Posted - 2005-01-24 : 10:57:58
Hi. I'm trying to come up with a standardized way of dealing with exceptions in my stored procedures and I have a question:
What is the difference between SET @err = @error and SELECT @err = @error? I was told that the SELECT version is not safe, since the select statement might fail, setting @error to an incorrect value. What if the SET statement fails? Isn't it the same thing?
Thanks
TIBM

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-24 : 11:21:25
>> I was told that the SELECT version is not safe, since the select statement might fail
nope

consider if you want to get @@rowcount and @@error. The only way to do this is
select @error = @@error, @rowcount = @@rowcount
For this reason I would always use select for @@error.

==========================================
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

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-24 : 11:29:58
I use this template for most every day error handling

http://weblogs.sqlteam.com/brettk/archive/2004/05/25/1378.aspx



Brett

8-)
Go to Top of Page

shmecher
Starting Member

10 Posts

Posted - 2005-01-24 : 12:22:05
Thanks for the replies.
I would still like to know, if I only have to select one variable (only @@error), which statement is better.
Thanks
TIBM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-24 : 13:12:28
Well to do proper error handling, you'd need both @@ERROR and @@ROWCOUNT, so there's no choice...

Use the search option on the site though....I remeber we had a debate about that...

Or look in books online



Brett

8-)
Go to Top of Page
   

- Advertisement -