I've scoured StackOverflow for a few hours, and tried different suggestions for similarly asked questions, but nothing passed the parameters correctly so far (double quotes, ^
).
Here's the short version of it:
@echo off
cd C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\
start /w "sqlcmd" sqlcmd.exe -S DBserverName -U username -P p@ssword -i C:\query.sql -s"," | findstr /V /C:"-" /B >c:\output.csv
Basically, I want to pass a rather long parameter containing delimiters. But the only way I see that happen is to use arguments. I'd like to keep it as simple as possible. Is this the only recourse? Can you offer an example how this might work?
Thanks in advance.
I'm not sure if it matters, but I think there should be a space between -s
and ","
But more importantly, your pipe construct is wrong. Your sqlcmd command is running in a new window, but your pipe is looking for output from the START command itself in the original window - and there isn't any.
You could get your command to work by escaping the pipe and redirection.
@echo off
cd C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\
start /w "sqlcmd" sqlcmd.exe -S DBserverName -U username -P p@ssword -i "C:\query.sql" -s "," ^| findstr /V /C:"-" /B ^>"c:\output.csv"
But there is no need to use START at all. Your script can simply execute sqlcmd directly, and everything is much simpler.
@echo off
cd C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\
sqlcmd.exe -S DBserverName -U username -P p@ssword -i "C:\query.sql" -s "," | findstr /V /C:"-" /B >"c:\output.csv"
You might also be running into problems with your password, depending on what characters are used. You might have to quote and/or escape the password, and sqlcmd.exe might have its own escape rules. If it does, then you might have to worry about escaping for both cmd.exe and sqlcmd.exe.