3

From msdn I learn, that the Variable Precedence of :Setvar X Y is higher, than that of sqlcmd -v X=Y.

I want to write a script, that uses the variables supplied to sqlcmd with the -v option, but which uses some default values, when run in Management Studio using SQLcmd mode.

Best there would be some way to supply the values to use somehow to the Management Studio without having to provide them in the script.

1

The precedence of setvar is the lowest. Try it out and see if it works.

1

Declare the sqlcmd variables in a parent script, then call the child script using the :r command, eg

:setvar var1 test1
:setvar var2 test2

:r c:\temp\yourSQLCMDScript.sql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.