executing .sql file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
daillest319
Posts: 27
Joined: 31 Jan 2012 14:45

executing .sql file

#1 Post by daillest319 » 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..

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)



Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: executing .sql file

#2 Post by Fawers » 21 Jun 2012 16:16

Both of them apparently need and external program: "sqlcmd". Do you have it?

Post Reply