16

How would you execute a stored procedure in SQL Server (using windows authentication) from a batch file?

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
Nitrodbz
  • 1,276
  • 1
  • 15
  • 25

3 Answers3

34

If you are using Sql Server 2005+, you can use sqlcmd utility.

Example:

sqlcmd -Q "exec storedProcName" -S YourServer -d YourDatabase -o C:\yourOutput.txt

dugas
  • 12,025
  • 3
  • 45
  • 51
5

With SQL Server 2005 and above you can use sqlcmd.exe. More info about how to use it:

http://msdn.microsoft.com/en-us/library/ms170572.aspx

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=109770

Robin V.
  • 1,484
  • 18
  • 30
4

You can use sqlcmd.exe See: MSDN usages

danseery
  • 486
  • 2
  • 11