Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need help for SQLCMD Expand / Collapse
Author
Message
Posted Saturday, January 31, 2009 8:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 2, 2011 10:31 PM
Points: 1, Visits: 43
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
Post #647616
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse