|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 31, 2010 1:05 PM
Points: 44,
Visits: 245
|
|
Hi,
is it possible to pass the servername as parameter to SQLCMD.
For eg: SQLCMD -E -S %servername% -i <input file> -o <output file>
servername is the parameter which i wish to pass..
This is basically to get some information from mulitple servers using SQLCMD
any help is appreciated!!!
Thanks!!!
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 1:13 PM
Points: 516,
Visits: 1,004
|
|
I do this all of the time using two batch files. The first one contains a %1 value for the server name, similar to below:
run.bat: sqlcmd -S %1 -E -i "X:\script.sql" -o "X:\%1_scriptout.txt"
The second one then calls this one passing in the name of the server as a parameter:
DeployAllServers.bat: call run.bat auca-sql02 call run.bat auca-sql01 call run.bat auca-sql01
I use it to deploy the same scripts to dozens of servers at a time and it works pretty well for that.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, May 31, 2010 1:05 PM
Points: 44,
Visits: 245
|
|
Thanks George.. That script work very well.. But I got an issue.
I run the SQLCMD for named instances too.. Suppose, when i execute my script again a named instance say "serverA\SQL2K". The below stmt
sqlcmd -S %1 -E -i "X:\script.sql" -o "X:\%1_scriptout.txt"
will be executed as
sqlcmd -S serverA\SQL2K -E -i "X:\script.sql" -o "X:\serverA\SQL2K_scriptout.txt"
This gives an error because the path "X:\serverA\SQL2K_scriptout.txt" does not exist.
Thanks!!!
|
|
|
|