Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2009

Tip: Looking for answers? Try searching our database.

Error Checking for Warning Messages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RMCompute - 02 Jul 2009 13:34 GMT
I have code to check for error messages after each SQL Statement as follows:

 Set @iErr = @@Error
 If @iErr <> 0
  Begin
   Set @vErrMess = '#00020 Main Process 020.'
   GoTo Error_Handler
  End

I would like to test for warning messages such as:

Warning: Null value is eliminated by an aggregate or other SET operation.

The value of @@Error remains zero after this warning message is issued.  Is
there another parameter to check which would indicate the error?
Thanks in advance.
Erland Sommarskog - 02 Jul 2009 23:05 GMT
> I have code to check for error messages after each SQL Statement as
> follows:
[quoted text clipped - 9 lines]
>
> Warning: Null value is eliminated by an aggregate or other SET operation.

There is no way to capture this message in SQL Server, only on client
level.

By the way, are you still on SQL 2000? If you are on SQL 2005 or later,
you should use TRY-CATCH for your error handling.

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

RMCompute - 02 Jul 2009 23:54 GMT
Thank you.  Actually, I didn't think there would be a way to trap it; just
wanted to be sure.  (Currently there's a bit too many DTS jobs to convert to
2005).

> > I have code to check for error messages after each SQL Statement as
> > follows:
[quoted text clipped - 15 lines]
> By the way, are you still on SQL 2000? If you are on SQL 2005 or later,
> you should use TRY-CATCH for your error handling.
--CELKO-- - 03 Jul 2009 01:13 GMT
>> Warning: Null value is eliminated by an aggregate or other SET operation.
The value of @@Error remains zero after this warning message is
issued.  <<

As an aside, you have to learn about the ANSI/ISO Standard error
handler model versus the VERY proprietary Sybase/SQL Server local
dialect if you are going to work in RDBMS.

This was a big debate point in ANSI X3H2 with cursors.  When is this
exception raised?  At DECLARE CURSOR? At OPEN CURSOR? At the FETCH for
the first row with that condition?

The answer is "Yes!!"  -- it is implementation defined.  Several
products did it differently, so we let them stand as valid.  Yet
another reason not to use cursors.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.