In a SQL script
GO
:setvar DefaultDataPath "%DataDrive%:\SQL\MSSQL\Data"
Will the script pick up %DataDrive% from the environment variables? If not, is there a way to get to the DataDrive environment variable from the SQL script?
In a SQL script
GO
:setvar DefaultDataPath "%DataDrive%:\SQL\MSSQL\Data"
Will the script pick up %DataDrive% from the environment variables? If not, is there a way to get to the DataDrive environment variable from the SQL script?
SQL server's sqlcmd supports script variables, which can be set in one of three ways:
:setvar as you do above-v optionIn other words, you can replace %DataDrive& with $(DataDrive) in your script and either set DataDrive as an environment variable before running, or pass e.g. -v DataDrive=D:\.to your script when running with sqlcmd.