Tools (SSMS, Agent, Profiler, Migration, etc.)
Enhance the sqlcmd utility to support a new "sqlcmd Command" that supports in-script assignment of scripting variable at a precedence level lower than "System-level environmental variables," the current lowest level source for variable assignment.
Basically, it assigns a value to a variable only if the variable does not yet exist via some other source.
I imagine a script something like this (where :defaultvar is the proposed, hypothetical new sqlcmd Command) ....
SELECT COUNT(*) FROM sys.objects;
then this command would always work:
sqlcmd -i "myscript.sql"
and this command would generate the expected results:
sqlcmd -i "myscript.sql" -v dbName=msdb