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.
    
        
            
                
                    
                        
                            
                                | 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 Serverraiserror('Step 1. Copy Production Backup file over to Sustainment SQL Server',1,1) with nowaitEXEC master..xp_cmdshell 'COPY \\server3\backup$\backupa_Full_LiteSpeed.BAK \\zvmpsesql03\backup$\backupa_Full_LiteSpeed.BAK'DECLARE @ReturnCode INT    DECLARE @err int,	@value intSELECT @ReturnCode = 0 SELECT @err= @@errorIF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollbackQuitWithRollback:EXEC usp_refreshscript_errorAppreciate insight. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     visakh16 
                                    Very Important crosS Applying yaK Herder 
                                     
                                    
                                    52326 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2011-10-19 : 10:54:33
                                          
  | 
                                         
                                        
                                          | shouldnt it beIF (@err <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |