Solved

Looking for good sample of TSQL error-handling

Posted on 2008-10-15
4
169 Views
Last Modified: 2010-04-21
Please point me to a page or provide me with a nice sample of error-handling with TSQL.
0
Comment
Question by:jdana
  • 2
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22719551
which sql server version?
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 250 total points
ID: 22719560
for v2005 and v2008 it's quite simple:

begin try
 do your code here...
end try
begin catch
 do your code here
end catch

inside the catch you can use error_number() and error_message() in order to understand which error happended

in sql 2000 you will have to use the @@error variable
0
 

Author Comment

by:jdana
ID: 22719641
Version 2005
0
 

Author Closing Comment

by:jdana
ID: 31506248
Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now