I'd like to issue the following command through SQLCMD:
IF DB_ID('My_DB') IS NOT NULL DROP DATABASE My_DB
There are a few caveats though...
- The database name is dynamic
- The program which is running the command (BuildForge) will not replace a variable if it appears within single quotes
So, I can't use:
-Q"IF DB_ID('${db_name}') IS NOT NULL DROP DATABASE ${db_name}
because it will use the literal ${db_name} in the single-quotes. I also can't use:
-Q"IF DB_ID("${db_name}") IS NOT NULL DROP DATABASE ${db_name}
because SQLCMD gets tripped up on the begin and end of the double quotes.
I know that I can create a script and pass in a parameter for the database name, but is there any way to do this in a single command line without a script? Any way to escape the double-quotes, etc.? Is there a BuildForge syntax that would let me build the string correctly?
Thanks!