Home All Groups Group Topic Archive Search About

The value of @@Error after Select statement

Author
12 May 2005 8:10 PM
Rosie
Hi,
I have been asked to check the value of @@Error after some of my Select
statements but I think that I don't need to. Could you please tell me in what
conditions we have none zero value in @@Error after a SELECT statement?

If SELECT doesn't return any record, it doesn't return any error (@@Error
will be 0).

Thank you,
Rosie

Author
12 May 2005 8:27 PM
Anith Sen
>> Could you please tell me in what conditions we have none zero value in
>> @@Error after a SELECT statement?

Not sure if I fully understood what you are asking, but if there is no error
in the last executed Transact-SQL statement, @@ERROR will be zero. I don't
think you can enumerate all the "conditions" which results in a non-zero
value for @@ERROR.

--
Anith
Author
12 May 2005 9:02 PM
Michael C#
For SELECT, it's probably a pretty narrow set of circumstances (lost
connection to server, table name or column names changed, inadequate
permissions, etc.).  BOL has an exhaustive list of error codes.

Show quote
"Rosie" <Ro***@discussions.microsoft.com> wrote in message
news:9253E784-7C80-4D4B-9019-D096E6C2E752@microsoft.com...
> Hi,
> I have been asked to check the value of @@Error after some of my Select
> statements but I think that I don't need to. Could you please tell me in
> what
> conditions we have none zero value in @@Error after a SELECT statement?
>
> If SELECT doesn't return any record, it doesn't return any error (@@Error
> will be 0).
>
> Thank you,
> Rosie
>
Author
13 May 2005 12:02 AM
Rosie
In sysmessages system table, is there any way that I can list all the errors
that are created by a Select statement? or I have to scan the table?

I'm looking for the temporary conditions that last very short period of
time(one second or less)  and raise error for a simple query with simple
joins (with no calculations) .

Thanks,
Rosie

Show quote
"Michael C#" wrote:

> For SELECT, it's probably a pretty narrow set of circumstances (lost
> connection to server, table name or column names changed, inadequate
> permissions, etc.).  BOL has an exhaustive list of error codes.
>
> "Rosie" <Ro***@discussions.microsoft.com> wrote in message
> news:9253E784-7C80-4D4B-9019-D096E6C2E752@microsoft.com...
> > Hi,
> > I have been asked to check the value of @@Error after some of my Select
> > statements but I think that I don't need to. Could you please tell me in
> > what
> > conditions we have none zero value in @@Error after a SELECT statement?
> >
> > If SELECT doesn't return any record, it doesn't return any error (@@Error
> > will be 0).
> >
> > Thank you,
> > Rosie
> >
>
>
>
Author
15 May 2005 8:08 PM
Michael C#
I would think that most errors that would occur because of a simple SELECT
statement would be mostly syntactical in nature or would be caused by other
underlying issues (such as connectivity issues, renamed or deleted
tables/columns), etc.

Checking the value of @@error after a SELECT statement might help you narrow
down the problem, but it probably will not be resolvable via trapping the
error in your front end; other than letting the developer or end user know
that the problem exists.  You'll need to fix the underlying problem...

You can select the error message that occurs using something like this:

SELECT * FROM master.dbo.sysmessages WHERE error = @@error

After a statement.  I think someone already mentioned that some statements
will terminate a batch so this isn't full-proof.

Show quote
"Rosie" <Ro***@discussions.microsoft.com> wrote in message
news:E80C8F31-975A-4789-9AA0-F22ED21E6C37@microsoft.com...
>
> In sysmessages system table, is there any way that I can list all the
> errors
> that are created by a Select statement? or I have to scan the table?
>
> I'm looking for the temporary conditions that last very short period of
> time(one second or less)  and raise error for a simple query with simple
> joins (with no calculations) .
>
> Thanks,
> Rosie
>
> "Michael C#" wrote:
>
>> For SELECT, it's probably a pretty narrow set of circumstances (lost
>> connection to server, table name or column names changed, inadequate
>> permissions, etc.).  BOL has an exhaustive list of error codes.
>>
>> "Rosie" <Ro***@discussions.microsoft.com> wrote in message
>> news:9253E784-7C80-4D4B-9019-D096E6C2E752@microsoft.com...
>> > Hi,
>> > I have been asked to check the value of @@Error after some of my Select
>> > statements but I think that I don't need to. Could you please tell me
>> > in
>> > what
>> > conditions we have none zero value in @@Error after a SELECT statement?
>> >
>> > If SELECT doesn't return any record, it doesn't return any error
>> > (@@Error
>> > will be 0).
>> >
>> > Thank you,
>> > Rosie
>> >
>>
>>
>>
Author
16 May 2005 7:00 PM
Rosie
Thanks!

Show quote
"Michael C#" wrote:

> I would think that most errors that would occur because of a simple SELECT
> statement would be mostly syntactical in nature or would be caused by other
> underlying issues (such as connectivity issues, renamed or deleted
> tables/columns), etc.
>
> Checking the value of @@error after a SELECT statement might help you narrow
> down the problem, but it probably will not be resolvable via trapping the
> error in your front end; other than letting the developer or end user know
> that the problem exists.  You'll need to fix the underlying problem...
>
> You can select the error message that occurs using something like this:
>
> SELECT * FROM master.dbo.sysmessages WHERE error = @@error
>
> After a statement.  I think someone already mentioned that some statements
> will terminate a batch so this isn't full-proof.
>
> "Rosie" <Ro***@discussions.microsoft.com> wrote in message
> news:E80C8F31-975A-4789-9AA0-F22ED21E6C37@microsoft.com...
> >
> > In sysmessages system table, is there any way that I can list all the
> > errors
> > that are created by a Select statement? or I have to scan the table?
> >
> > I'm looking for the temporary conditions that last very short period of
> > time(one second or less)  and raise error for a simple query with simple
> > joins (with no calculations) .
> >
> > Thanks,
> > Rosie
> >
> > "Michael C#" wrote:
> >
> >> For SELECT, it's probably a pretty narrow set of circumstances (lost
> >> connection to server, table name or column names changed, inadequate
> >> permissions, etc.).  BOL has an exhaustive list of error codes.
> >>
> >> "Rosie" <Ro***@discussions.microsoft.com> wrote in message
> >> news:9253E784-7C80-4D4B-9019-D096E6C2E752@microsoft.com...
> >> > Hi,
> >> > I have been asked to check the value of @@Error after some of my Select
> >> > statements but I think that I don't need to. Could you please tell me
> >> > in
> >> > what
> >> > conditions we have none zero value in @@Error after a SELECT statement?
> >> >
> >> > If SELECT doesn't return any record, it doesn't return any error
> >> > (@@Error
> >> > will be 0).
> >> >
> >> > Thank you,
> >> > Rosie
> >> >
> >>
> >>
> >>
>
>
>
Author
12 May 2005 10:54 PM
Itzik Ben-Gan
If the SELECT fails for any reason, @@error would produce a non-zero value,
e.g.,

select 1/0
select @@error

select log(0)
select @@error

Note that some errors terminate the batch, so you won't have a chance to
trap those with T-SQL (e.g., conversion error, deadlock):

select 'a'+1
select @@error


--
BG, SQL Server MVP
www.SolidQualityLearning.com


Show quote
"Rosie" <Ro***@discussions.microsoft.com> wrote in message
news:9253E784-7C80-4D4B-9019-D096E6C2E752@microsoft.com...
> Hi,
> I have been asked to check the value of @@Error after some of my Select
> statements but I think that I don't need to. Could you please tell me in
what
> conditions we have none zero value in @@Error after a SELECT statement?
>
> If SELECT doesn't return any record, it doesn't return any error (@@Error
> will be 0).
>
> Thank you,
> Rosie
>

AddThis Social Bookmark Button

Post Other interesting topics