Sreedhar
Sreedhar

Reputation: 30025

User Input - DOS batch file

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

Upvotes: 2

Views: 6548

Answers (2)

Ken White
Ken White

Reputation: 125669

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.

Upvotes: 1

jball
jball

Reputation: 25014

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

Upvotes: 4

Related Questions