|
Answer» I am running a batch to check if a database EXIST if it does I need to exit the batch or if the database doesn't exist then to continue with the INSTALL what am I doing wrong here any help is much appreciated
Code: [Select]@ECHO OFF net start MSSQLSERVER net start SQLSERVERAGENT osql -E -n -W 300 -o "c:\checkdbexist.txt" -i c:\checkdb.sql" find "Database Exists" "c:\checkdbexist.txt" IF ERRORLEVEL 0 GOTO :QUIT :QUIT exit find "Database Does Not Exists" "c:\checkdbexist.txt" IF ERRORLEVEL 0 GOTO :OK :OK pause The IF statement in a batch FILE is not a a block structure. It is a one LINE thing. The one line has to tell it to goto a blcok of code.Then you have to have some more GOTOs to define one or more blocks. You did not make the :QUIT part of a block. And you need to have a NOQUIT block and an a DONE point May this is what you want. IF ERRORLEVEL=0 GOTO QUIT GOTO NOQUIT :QUIT blah blah blah THIS IS A BLOCK GOTO DONE :NOQUIT blah blah blah THIS IS THE OTHER BLOCK :DONE
Batch file programming has to be the worst thing ever invented! Code: [Select]@ECHO OFF net start MSSQLSERVER net start SQLSERVERAGENT osql -E -n -w 300 -o "c:\checkdbexist.txt" -i c:\checkdb.sql" find "Database Exists" "c:\checkdbexist.txt" IF ERRORLEVEL 0 GOTO :QUIT
You will go here whatever the errorlevel <-----------------------------------------
:QUIT exit
Therefore you will never get here <-----------------------------------------------
find "Database Does Not Exists" "c:\checkdbexist.txt" IF ERRORLEVEL 0 GOTO
But even if you could <--------------------------------------- You will go here whatever the errorlevel <-----------------------------------------
:OK pause
|