Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure Calling Batch File

Status
Not open for further replies.

jhampton13

Programmer
Dec 19, 2003
5
GB
I would like to call a batch file from a stored procedure, something like

If (this happens)
then (call xxxx.bat)

I know there are some ways of doing this by stepping outside of the database into the O/S and then calling the batch file, but I have been searching for an easier way. If anyone knows a way that I can call the batch file to run directly from the stored procedure, it would be greatly appreciated.. Thanks...
 
You can use the extended stored procedure xp_cmdshell in the master database for this.
 
jhampton13, what do you want to do with the batch file? Grab the file and then load it?

 
Ok, there are tow utilities, isql.exe and isqlw.exe, you can use them in a .bat file like this:

isql -SserverName -UuserName -Ppassword -isomefile.sql

where the content of somefile.sql could be for example
use somedatabase
go
select * from sometable
go

Ion Filipski
1c.bmp
 
Oh, .bat...my mind is stuck in bulk insert mode!
Not sure if you can call isql from a batch file. It'd be a good thing to know though!

 
Thanks for your help. I'm pretty sure that if I use an extended stored procedure, this will work ok. Thanks again
 
Be very careful about permissions on xp_cmdshell.
It is very very dangerous.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top