Groups | Blog | Home
all groups > sql server programming > april 2004 >

sql server programming : @@error not displaying


Thomas Scheiderich
4/21/2004 11:29:27 PM
Why can I not print @@error directly? In the following code, @@error
displays as 0 (when it should be 220 - overflow error).

********************************
declare
@temp smallint,
@error smallint

select @temp = 32000 + 32000

print "@@error"
print @@error
**********************************

If I change the code to move @@error into a variable (@error) and
display the variable, it displays 220 correctly - as so:

********************************
declare
@temp smallint,
@error smallint

select @temp = 32000 + 32000

select @error = @@error
print @error
**********************************

Why is this?

Tom.
Hari
4/22/2004 12:12:09 PM
Hi,

@@error should be the very next statement after the error, In your first
case you are using the print "@@error" first. This case the actual value
in the @@error will be reinitialsed to "0"

code should be

declare
@temp smallint,
@error smallint
select @temp = 32000 + 32000
print @@error

or

declare
@temp smallint,
@error smallint
select @temp = 32000 + 32000
select "@@error"= @@error

Thanks
Hari
MCDBA






[quoted text, click to view]

AddThis Social Bookmark Button