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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With