How I get a return code from SQL file - if I excuted ISQL?

271 Views Asked by At

I execute in a batch script a SQL file to backup my database. I want from the sql file / script a return code to see if is success or not.

I excuted this

isql -S %DBSID% -D %DBSID% -U %DBUSER% -P%DBPASS%  -X -i "C:\example\backup.sql" >> "C:\logs\fullbackup.log"

Anyone can help?

1

There are 1 best solutions below

1
On

I am not sure if isql sets an %errorlevel% or return code but, if it does you can use something like this:

isql -S %DBSID% -D %DBSID% -U %DBUSER% -P%DBPASS%  -X -i "C:\example\backup.sql" >> "C:\logs\fullbackup.log"
If %errorlevel% NEQ 0 (echo error occured) else (echo success)

This will simply check for an %errorlevel% and if it's 'not equal too' NEQ '0' then it will simply echo "error occured" otherwise "success".

You can experiment with the if conditions or if you require more help, you can also refer to the site.