Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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

share|improve this answer
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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