executing .sql file
Posted: 21 Jun 2012 09:57
I'm trying to wirte a srcipt so i can run a .sql file and connect to the sql server and output the file as a .xls I've looked around i found different code....all are very similar but they are not working one code looks like below... Also for password its set to Windows Authentication so i have no idea how to apply that to the script..
or
Code: Select all
@echo off
cls
set /p SName=Server Name :
set /p UName=User Name :
set /p Pwd=Password :
set /p DbName=Database Name :
set /p choice=ARE YOU SURE TO EXECUTE SCRIPTS in %DbName% (y/n) ?
if '%choice%'=='y' goto begin
goto end
:begin
if exist _Deploy.txt del _Deploy.txt
@echo on
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -I -i "UDDs"\UDDs.sql >> _Deploy.txt 2>&1
@notepad _Deploy.txt
:end
or
Code: Select all
@echo off
set /p sname= Please enter the servername:
set /p dbname= Please enter the databasename:
set /p pwd= Please enter the password:
sqlcmd -E -S %sname% -D %dbname% -P %PWD% -i "C:\location\your query.sql" -b)