I need to write a batch script that calls a SQL Server query and runs a procedure in a SQL Server database and stores the result log in a file.
Asked
Active
Viewed 338 times
-1
-
3Ummmm....how could we do that? You have provided exactly no information at all. – Sean Lange May 12 '17 at 20:27
-
1Sounds like Friday afternoon homework assignment for the weekend! – SS_DBA May 12 '17 at 20:28
-
Here I am trying to think of what kinds of sprites someone would want to store in a log file... – Jacob H May 12 '17 at 20:32
-
I think you can do that using the SQLCMD command. – Varun Mehta May 12 '17 at 20:46
1 Answers
1
You can create a .bat file with contents like this:
cd %0\..
sqlcmd -S YourServerName -d "YourdatabaseName" -U SqlLonginuserName -P Password -o "C:\Script_Output.txt" -p 1 -i "c:\LocationOfSQLScript.sql"

JBdev
- 353
- 1
- 10