Search code examples
sqlsql-serverbatch-filesqlcmd

Write a batch to check and return values from SQL and then run scripts determined by the return


Is it possible to write a batch file that will check and return a value from SQL and run a particular set of scripts depending of the return value from SQL.

For example,

If this returns a version 5 value:

sqlcmd -U *** -P *** -S127.0.0.1 -Q "checkversion.sql" 

Run version 5 scripts, but ignore 1, 2, 3 and 4.

But if this returns a version 6 value:

sqlcmd -U *** -P *** -S127.0.0.1 -Q "checkversion.sql" 

Run version 5 and version 6 scripts but ignore 1, 2, 3 and 4.


Solution

  • Do it all in TSQL because you can nest stored procedures