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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

share|improve this answer

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

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.