June 25, 2004 at 4:43 am
In the following example code, I want to check the value of @@ERROR after an error has occured. This code returns a error on the SELECT, and doesn't go any further.
Will SQL only get to the IF statement based on a certain error severity?
SELECT * FROM NoTable
IF @@ERROR != 0
PRINT 'ERROR!'
June 25, 2004 at 5:03 am
June 25, 2004 at 10:48 am
try...
if @@error <> 0
begin print 'error' end
June 28, 2004 at 4:34 am
For a detailed explanation of error handling in T-SQL, read an excellent article by Erland Sommarskog, SQL Server MVP:
http://www.sommarskog.se/error-handling-II.html
Razvan
June 28, 2004 at 2:00 pm
Once you find that @@Error is not 0, is there a way to retrieve actual SQL error message? Is there a variable like that?
Thanks
June 28, 2004 at 2:16 pm
Sysmessage is the way of the warrior...
declare @err int
select 1/0 from syscolumns
select @err = @@error
select * from master..sysmessages where error = @err
June 28, 2004 at 3:28 pm
Thanks
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply