Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Unable to run sqlcmd using batch

$
0
0
Hi All I use the following batch to run list of scripts in folder [code="other"]@echo offset scripts=%~dp0\_scripts.txtset Instance=%1set DataBase=%2set Password=%3set userName=%4if "%instance%" equ "" set instance=-".\MSSQL"if "%DataBase%" equ "" set DataBase=-"Northwind"if "%Password%" equ "" set Password=-"123"if "%userName%" equ "" set userName=-"sa"remrem Make sure the scripts file exists.remif not exist %scripts% ( echo. echo Scripts file "%scripts%" does not exist. echo. goto error) remrem Clean output of any previous runsremif exist %~dp0\__tmp* del /q %~dp0\__tmp*remrem Apply all SQL scripts in order as listed in _scripts.txtremrem NOTE: if any of the script filenames contain a space, thisrem for loop will only see the 1st component of the filename,rem and then fail (file not found). Do not use spaces in therem script filename.remfor /f "delims==" %%x in (%scripts%) do ( echo. echo Applying script %%x... if not exist %CD%\%%x ( echo. echo ERROR: script does not exist '%CD%\%%x' echo. goto error %%x ) rem rem Make sure script exists rem if not exist "%~dp0\%%x" ( echo. echo ERROR: script does not exist '%~dp0\%%x' echo. goto error ) rem rem Run the script, show the output on stdout and tee this to a rem file with the same name as the script, prefixed with __tmp_ rem sqlcmd -S%instance% -d%DataBase% -u%userName% -p%Password% -i"%~dp0\%%x" -o"%~dp0\__tmp_%%x") echo.echo Done!goto end:errorecho.endlocalexit /b 1:endendlocalexit /b 0[/code]it gives error Sqlcmd: '-sa': Unexpected argument. Enter '-?' for help.any idea how to fix that

Viewing all articles
Browse latest Browse all 3145

Trending Articles