• michael.farrow (3/1/2015)


    In a batch file, I'm using BCP ... || goto ERROR_HANDLING from which I then capture %ERRORLEVEL%. It works perfectly, but sometimes %ERRORLEVEL% is zero, and I was wondering why.

    You might want to try adding the following to the top of your script:

    SETLOCAL ENABLEDELAYEDEXPANSION

    And then check the value of (please note the use of ! instead of %):

    !ERRORLEVEL!

    I had to do that in order to get the return code from SQLCMD.EXE in a CMD script. Without enabling delayed variable expansion, %ERRORLEVEL% was always set to 0.

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR