Need help for SQLCMD

  • Hi,

    I am using SQLCMD in a batchfile with SET NOEXEC ON option and -i option to execute a SQL files in a folder.

    My requirement is just to compile the code using batchfile and not to execute it.

    Now when SQLCMD compiles SQL script file; and if it encouneters any compilation error like invalid object name or column does not exist; I want some kind of error code/message to be return so that I can trap that compilation error. Currently I have used ERRORLEVEL but it returns 0 only. Please help me in this.

    How do I trap compilation error return from SQLCMD?

    Below is my sample code:

    SQLCMD -Sdhananjay -E -dTest -Q "SET NOEXEC ON"

    for %%f in (*.sql) Do (

    echo -------------------------------------------------------------------------

    echo %date% - %time%

    if exist *.sql echo Compiling "%%f" script...

    SQLCMD -Sdhananjay -E -dTest -Q"SET NOCOUNT ON" -i "%%f" -b -h-1

    echo %ERRORLEVEL%

    echo -------------------------------------------------------------------------

    )>> Alter-%d%.log

Viewing 0 posts

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