SimpleSqlExec
SimpleSqlExec copied to clipboard
Support variable substitution
Allow substitution of $(var_name)
variable.
This also requires handling:
-
-v
command-line switch -
:setvar
SQLCMD command - checking all 3 levels of environment variables
-
-x
ignore scripting variables
The following notes are taken from the MSDN page for the sqlcmd Utility:
Variable Precedence (Low to High)
- System-level environmental variables.
- User-level environmental variables
- Command shell (SET X=Y) set at command prompt before running sqlcmd.
- sqlcmd -v X=Y
- :Setvar X Y
NOTES:
- SQLCMD processes commands and variable substitution per each batch!
- Scripting variable names are case-insensitive
- If no value is assigned to a sqlcmd environment variable, the variable is removed.
- Using
:setvar VarName
without a value clears the variable. - SQLCMD commands inside of block comments and string literals are not processed.
- See also: Use sqlcmd with Scripting Variables