How can i set variables in SQLCMD

346 views Asked by At
SQLCMD 
-S <serverName> 
-U sa -P <password> 
-d <DatabaseBase>
-Q "select top(1) * from table order by 1 desc" 
-o "new.propertie"

When i am using the instead of it is not working

Variable i created

:setvar servaername "ServerName"
1

There are 1 answers

0
jradich1234 On

I think your issue could be that variable names are case sensitive. You have "serverName" and "ServerName", in your example.

https://msdn.microsoft.com/en-us/library/ms162773.aspx

Variables :Setvar [ "value" ] Defines sqlcmd scripting variables. Scripting variables have the following format: $(VARNAME).

Variable names are case insensitive.