I'm trying to use a Windows command prompt on Server 2012 R2 to run a batch file with the following command line. I want to run an SQL command (sqlcmd) and return the results to the console window.
This is what I'm currently trying, but sqlcmd
keeps throwing back:
Sqlcmd: 'test': Invalid argument. Enter '-?' for help.
FOR /F "tokens=* USEBACKQ" %%F IN (`sqlcmd -S localhost -E -i "backup.sql" -v dbname="test"`) DO (
Echo %%F
)
Note: I have also tried to run just this sqlcmd
command (above) in a command prompt with no issues. It's like it does not like the FOR /F
loop or something.
However if I try it without parameters/variables it works perfectly!
FOR /F "tokens=* USEBACKQ" %%F IN (`sqlcmd -S localhost -E -i "backup.sql"`) DO (
Echo %%F
)
Does anyone know a way around getting the variables passed to my SQL query using sqlcmd
, Windows CMD, as well as a FOR /F
loop such as in my first example?