Make a .bat file with the following content (read the REM comments for details):
REM This script expects these parameters: Path of file with query to run, path of file with parameters, path of file to save output in.
set SQLFILE=%1
set PARAMFILE=%2
SET OUTPUTFILE=%3
SET TEMPFILEPATH=C:\Temp\tempsqlstatementt.sql
REM Combine SQL command and parameters into one temporary file.
copy /B %SQLFILE% + %PARAMFILE% %TEMPFILEPATH%
REM Execute combined SQL command and write to specified output
sqlcmd -S myServer\instanceName -i C:\Temp\tempsqlstatementt.sql -o %OUTPUTFILE%
REM Cleanup the temp file.
DEL %TEMPFILEPATH% /F /Q
You can call this bat file like this:
ExecuteWithParams QueryFile ParamFile OutputFile
Here it is again but I put in actual file paths:
C:\Users\You\>ExecuteWithParams.bat QueryFile.sql ParamFile.sql OutputFile.txt
Also, if sqlcmd isn't on the path you'll have to put the path to sqlcmd into the bat file.