Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 DTS Execute SQL Task + stored proc error handling

Author  Topic 

Crowknee
Starting Member

5 Posts

Posted - 2007-02-20 : 20:41:04
Hi All,
I am using SQL Server 2000 (SP2) and am designing a DTS package.
I have an Execute SQL Task that calls a stored procedure.
The trick here is that I want to return a result when a particular error occurs in the stored procedure. Namely, if I try to insert a row that violates a null insert constraint (or similar). The stored procdure has a statement like :

INSERT INTO mytable (not_null_col) VALUES (null)
IF (@@ERROR > 0)
SELECT 'My error statement' as mymsg


When I run this in the Query Analyzer, this works beautifully - the error message from SQL Server appears in the Messages window, and my error message is returned in Grids.
The problem is that the Execute SQL Task seems to just chuck everything in once it finds a statement that returns an error. My error SELECT statement is never run - even if I remove the IF statement!
Is this just a limitation of the Execute SQL Task? Is there another way around this? In reality, the error I want to return will need to run a query to get a bit more information about the error so I really do need to have the task continue.
Any help is greatly appreciated,
Steele.
   

- Advertisement -