To list all available SQLCMD Scripting variables, do the following: Step 1: Go to DOS prompt and open up SQLCMD Step 2: type :listvar which would list all SQLCMD scripting variables. In the screenshot you can see that the SQLCMDEditor and SQLCMDINI variable which we overwrote in the previous posts here and here are displayed. Almost all of the other variables are self-explanatory :) Creating our own local variables: :setvar DB1 testBed :setvar DB2 Adventureworks use $(DB1) go Select getdate(); go use $(DB2) go select top 5 city from person.address go Point to note: 1. If you execute :listvar again you can find these newly created variables getting listed there now. But please note that these local variables would be alive only till the life of the current session. i.e., If you exit out of SQLCMD once and come back and type :listvar these variables would be missing there. 2. Always the variables which we create will be in Uppercase only . Just try creating something like this: :s
I write about things which I am passionate about.