Error handling in T-SQL using compound statements

Error handling in T-SQL using compound statements

Post by Jeroen Ritmeije » Sat, 01 Dec 2001 02:56:57



Here is one for you that I have difficulties solving. I want to check if the
following statement succeeds

    INSERT INTO StoreOrderLine EXEC SMExportOrderLines 55056

For testing purposes I perform a RAISERROR in SMExportOrderLines. If I call


it internally executes the INSERT command last.

Does anyone have a solution for this? Is it possible to return a result code
from SMExportOrderLines and set that to a local variable which I can then
test?

 
 
 

Error handling in T-SQL using compound statements

Post by Umachandar Jayachandra » Sat, 01 Dec 2001 14:06:46


    Please post some sample code instead of verbal descriptions. How does
your RAISERROR statement look? What is the severity of the error? There are
so many different ways to call RAISERROR. Here is an example that will work
fine:

create proc #s as select 1 raiserror( 'ERROR!', 16, 1 )
go
create table #t( i int )
insert into #t ( i ) exec #s

drop proc #s
drop table #t

--
Umachandar Jayachandran
SQL Resources at http://www.umachandar.com/resources.htm
( Please reply only to newsgroup. )

 
 
 

Error handling in T-SQL using compound statements

Post by Jeroen Ritmeije » Sat, 01 Dec 2001 18:43:56


Your example works, however I am doing the same thing in my code and it
doesn't work there. I was hoping this was a well known problem and therefore
I did not include any code.

Anyway, I created an example to reproduce the problem. Please note that two
different databases are involved.

Database1
-- This procedure has obviously been simplified from it's original version.

BEGIN
    raiserror( 'ERROR!', 16, 1 )
END

Database2
CREATE PROCEDURE Test AS
BEGIN







    INSERT INTO SMStoreOrderLine


END


>     Please post some sample code instead of verbal descriptions. How does
> your RAISERROR statement look? What is the severity of the error? There
are
> so many different ways to call RAISERROR. Here is an example that will
work
> fine:

> create proc #s as select 1 raiserror( 'ERROR!', 16, 1 )
> go
> create table #t( i int )
> insert into #t ( i ) exec #s

> drop proc #s
> drop table #t

> --
> Umachandar Jayachandran
> SQL Resources at http://www.umachandar.com/resources.htm
> ( Please reply only to newsgroup. )

 
 
 

1. SQL-Procedure called with ODBC terminates on error and ignores TSQL-error handling

We call stored procedures on SQL-Server with ODBC.  The stored procedures

(MSQuery) a procedure stops when an error occurs and only the following
print statements in the procedure code are executed. The same procedure
called with DbLibrary (ISQL/W) continues.  How can we configure ODBC to
make  procedures be executed the same way ?

Stefan

create  procedure test
as
create table #tmp(Nr int not NULL)
insert into #tmp(Nr) values (NULL)

    GOTO ON_ERROR
return 0
ON_ERROR:
    PRINT   'Error message 1 (Print)'
    SELECT  'Error message 2 (Select)' -- is not executed, if procedure
test is called with ODBC
    return -1

2. Transfer from MS SQL to hsqldb

3. Compound statement error

4. Experienced PICK Professionals wanted for 2 Reg/FT openings in Phila./South Jersey area

5. TSQL login error handling?

6. IDENTITY-column problem

7. Handling data type conversion errors in TSQL

8. Semicolons in Password Possible? (ODBC Connect String)

9. Error handling in TSQL

10. Functioanlity Request: Error handling in TSQL-Debugger

11. 'compound' sql statement

12. Compound SQL Statements & ADO

13. Problems w/compound SQL statement