Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Get sql statement which throws exception...
Get sql statement which throws exception while executing in try block
Rate Topic
Display Mode
Topic Options
Author
Message
anand.mind
anand.mind
Posted Monday, September 24, 2012 3:39 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, October 09, 2012 11:46 AM
Points: 17,
Visits: 47
Hi,
I need to get sql statement, which throws an exception while executing in try block.
E.g.
Begin Try
SELECT 1/0
End Try
Begin Catch
Select ERROR_MESSAGE()
End Catch
Result should like this-
Error Message: Divide by zero error encountered.
SQL Statement: SELECT 1/0
Can anybody help me out to get this result?
Thanks & Regards,
Kumar Anand
Post #1363383
davidandrews13
davidandrews13
Posted Monday, September 24, 2012 3:45 AM
SSC-Addicted
Group: General Forum Members
Last Login: Today @ 10:15 AM
Points: 463,
Visits: 2,714
you can use SELECT ERROR_LINE() to get the line the error occurred on.
Post #1363388
Adi Cohn-120898
Adi Cohn-120898
Posted Monday, September 24, 2012 3:47 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 1:01 PM
Points: 2,023,
Visits: 4,947
I assume that you are using a log table and in the catch block you want to log the information. In that case you can also use the error_line() and error_procedure() function to get the procedure's name and at what line the error occurred.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1363390
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.