user1464922
user1464922

Reputation: 381

@@error returns 0 although the condition is not satisfied

raiserror('Hello world', 16, 1) 
if (@@error > 0)
    print @@error 

Why does it even return 0? If shouldn't allow to do so.

Upvotes: 0

Views: 114

Answers (1)

Andrew
Andrew

Reputation: 5277

@@Error stores the error for only a single call on the immediate line after the error. See http://technet.microsoft.com/en-us/library/ms188790.aspx Try this

declare @x int
raiserror('Hello world', 16, 1) 
set @x=@@error 
if (@x > 0)
   print @x 

Upvotes: 1

Related Questions