tags:

views:

376

answers:

2

I get a bat file as below:

@ECHO Executing scripts...
PAUSE 

for %%X in (*.SQL) do SQLCMD -S localhost -d CTL  -I -i "%%X" >> ResultScript.txt

pause

In this I want to has user inputs for localhost (Sql server instance) and CTL (database). How can this be achieved in DOS (os: WinXP)

Thanks

+2  A: 
SET /P variable=PromptString

So your batch file would be something like this

@ECHO Executing scripts... 
PAUSE  
SET /P sqlServer=Please enter SQLServer: 
SET /P CTL=Please enter CTL:
for %%X in (*.SQL) do SQLCMD -S %sqlServer% -d %CTL%  -I -i "%%X" >> ResultScript.txt 

pause
jball
A: 

Use parameter markers, where %1 refers to the first parameter, %2 the second, and so forth.:

for %%X in (*.SQL) do SQLCMD -S %1 -d %2  -I -i "%%X" >> ResultScript.txt

If your batch file was called ExecScript.bat, your user would run it as

ExecScript instancename databasename

You'll probably want to add a test above the for loop to make sure both parameters are passed in. Running SQLCMD with a blank instance and database wouldn't work too well.

Ken White