SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help for SQLCMD


Need help for SQLCMD

Author
Message
dk0036173
dk0036173
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search