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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SQL server’s
sqlcmdsupports script variables, which can be set in one of three ways::setvaras you do above-voptionIn 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 withsqlcmd.