Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 stored proc to exec .sql batch file

Author  Topic 

Ex
Posting Yak Master

166 Posts

Posted - 2005-05-05 : 23:32:05
hey guys what stored proc can i use to exec a .sql file?

also is there any way to give a .sql file a paramter when you run it?

------------------------------------------------------------------

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Rich Cook

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-05 : 23:38:06
The one you write.

(But I'm guessing it will be something like xp_cmdshell calling osql)


Damian
Ita erat quando hic adveni.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-05-05 : 23:39:16
You should load it into a .PDF file, import it into a BLOB, then use an extended stored procedure to read the contents of the .PDF file. You could load that into a temp table and use dynamic SQL with a cursor to execute it.



MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-05-05 : 23:40:30
Ya know, you can also make three left turns instead of one right turn too...
Go to Top of Page

Ex
Posting Yak Master

166 Posts

Posted - 2005-05-05 : 23:49:35
though there might be a nice easy way to do it but i will read the file into my app and exec it through the db connection

------------------------------------------------------------------

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Rich Cook
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-05-05 : 23:51:26
Look at osql in Books Online Ex. It should give you the information you need. You can execute the .sql file with that. The problem will be adding parameters.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Ex
Posting Yak Master

166 Posts

Posted - 2005-05-05 : 23:53:32
that will do the trick, thanks derrick

------------------------------------------------------------------

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Rich Cook
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-05-06 : 00:01:29
It's pretty easy to pass parameters using a batch file, the only problem is that they are based on number/position, so you must ensure you pass them in the proper order. Paste the following into a text file and save it as northwind.bat:

osql -Sserver -E -n -Q"select * from northwind..orders where customerid='%1'"

Then run it like so:

EXEC master..xp_cmdshell 'northwind.bat VINET'

Using this technique is probably not too practical with a .SQL file though, but it should give you some ideas. Probably better to just make a stored procedure out of the script.
Go to Top of Page
   

- Advertisement -