The standard way to feed input into a program is preparing the input and redirecting it via a |
pipe. For example:
(
echo Select Number FROM Table1
echo GO
echo . . .
echo EXIT or QUIT or BYE...
) | sqlcmd -S <servername>\<instancename>
However, if the purpose of your Batch file is just to execute sql commands (and have no Batch logic), an easier way is to prepare a .txt
file with the same input you would type via the keyboard:
sqlcmd -S <servername>\<instancename>
Select Number FROM Table1
GO
... and then feed that file into cmd.exe this way:
cmd < theFile.txt
In this case, don't forget to insert both the exit command for sql AND the exit
command for cmd.exe!