Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 exception handling questions
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shmecher
Starting Member

10 Posts

Posted - 01/24/2005 :  10:57:58  Show Profile  Reply with Quote
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

United Kingdom
12543 Posts

Posted - 01/24/2005 :  11:21:25  Show Profile  Visit nr's Homepage  Reply with Quote
>> 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 - 01/24/2005 :  11:29:58  Show Profile  Reply with Quote
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 - 01/24/2005 :  12:22:05  Show Profile  Reply with Quote
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 - 01/24/2005 :  13:12:28  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000