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
 SQL Server Administration (2000)
 Error Handling

Author  Topic 

netwerkassist
Starting Member

13 Posts

Posted - 2011-10-19 : 10:35:18
I'm looking for some help with error handling on one sql statement which is part of a larger script. I want the script to execute a stored procedure (which will email me) if an error is produced. However the stored procedure still executes even though there is no error.

Here's the code:
-- *** Step 1. Copy Production Backup file over to Sustainment SQL Server

raiserror('Step 1. Copy Production Backup file over to Sustainment SQL Server',1,1) with nowait

EXEC master..xp_cmdshell 'COPY \\server3\backup$\backupa_Full_LiteSpeed.BAK \\zvmpsesql03\backup$\backupa_Full_LiteSpeed.BAK'
DECLARE @ReturnCode INT
DECLARE @err int,
@value int
SELECT @ReturnCode = 0
SELECT @err= @@error
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

QuitWithRollback:
EXEC usp_refreshscript_error

Appreciate insight.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-19 : 10:54:33
shouldnt it be

IF (@err <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -