Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 1st, 2007, 08:22 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default Error handling with SQL Server


I have created a stored procedure where 3 conditions are applied, like

if Condition 1 is true
select blah blah......

if Condition 2 is true
select blah blah......

if Condition 3 is true
select blah blah......

Now to handle the error, I have written with each condition that
if (@@error <> 0)
--do some work

What I want to know is, that rather than repeating the error condition in all the conditions, can't I write it universally anywhere so that if error comes in any of the conditions, some error handling is done.


Fortune favours the brave, so don't regret on missed oppurtunities.
Reply With Quote
  #2 (permalink)  
Old January 1st, 2007, 08:32 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

Unfortunately that's the only option in SQL 2000, if using SQL 2005 you can use try/catch blocks.


Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old January 2nd, 2007, 07:16 PM
Friend of Wrox
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts

Your basically correct but here is another idea.

Error handeling only gives you the error if you trap for it immediately after your command, similar to @@rowcount. You can repeat a line after every command and store your error number in a variable and then do a goto an error handeling section on the bottom of your proc (I like this method). But you have to store the error code right where it happened. So bascially you have to put something after every command to trap the error but then you can put all your error handeling code in one area rather than immediately after the error was trapped. I find this much more organized particularly if you want to store your errors someplace, you don't have to repeat that code that way.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Reg. SQL Server does not exist error Arsi SQL Server 2000 1 June 11th, 2008 11:20 AM
C# handling SQL Server exceptions booksnore2 General .NET 3 September 16th, 2006 09:40 AM
error handling in ms sql starnet SQL Server 2000 1 July 19th, 2006 12:01 PM
SQL Server Error azwildcat4ever SQL Server 2000 3 December 22nd, 2004 11:36 AM
Server.Execute() Error handling nickelsberry Classic ASP Professional 2 April 14th, 2004 04:45 PM

All times are GMT -4. The time now is 09:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.