Adding a raise error when using batch scripts in SQL

  • I call a batch command to be ran in a SQL job.

    My current syntax is this:

    DECLARE @rc int

    EXECUTE @rc = master.dbo.xp_cmdshell 'c:\SQLBAT~1\Filemovedata.bat'

    PRINT @rc

    IF (@rc = 0)

    PRINT 'Move Successful'

    ELSE

    PRINT 'Move Failed'

    Obviously the success/fail of this script is false and deceiving. The SQL script runs correctly but I have no stop gaps if the actual .bat file fails....

    any possibility to do this?

    Looking for suggestions/alternatives..

    Thanks

  • put an errorhandler at the end of the batch script something like

    Do stuff

    call batch script

    IF @rc <> 0

    GOTO ErrHandler

    do more stuff

    GOTO Exit

    ErrHandler:

    do some stuff

    Exit:

    GO

  • Ok so place the error within the batch file....thanks

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply