sqlcmd: Add new Command to Assign Variable Default Values - by JediSQL

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 776539 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 1/14/2013 3:38:47 PM
Access Restriction Public


I would like to create sqlcmd scripts that:
1) have $(variables) so I can control behavior at runtime, and
2) can also work without any specifying any variable values by -v or environment variables.

The :setvar command can ensure that value-assigned variables exist, but there is no ability to assign runtime values because the :setvar command has the highest precedent.

It would be nice if there was a new sqlcmd command, e.g., :defaultvar, that had a precedence lower than "System-level environmental variables."  This way a script would always have its variables defined, AND they could also always be overridden at run time.

This also has the benefit of not altering the behavior of the :setvar command as proposed in this connect thread:
"In Sqlcmd scripts setvar should have a lower precedence than command line variable assignment" (ID = 382007)
Sign in to post a comment.
Posted by Joe Egan on 9/5/2013 at 4:49 PM
Posted by Microsoft on 1/21/2013 at 9:19 AM
Thanks for your feedback. We will review the suggestion for the next release.