SimpleSqlExec icon indicating copy to clipboard operation
SimpleSqlExec copied to clipboard

Support variable substitution

Open SqlQuantumLeap opened this issue 8 years ago • 0 comments

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)

  1. System-level environmental variables.
  2. User-level environmental variables
  3. Command shell (SET X=Y) set at command prompt before running sqlcmd.
  4. sqlcmd -v X=Y
  5. :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

SqlQuantumLeap avatar Dec 14 '15 20:12 SqlQuantumLeap