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
 Import/Export (DTS) and Replication (2000)
 run sql queries stored in a text file

Author  Topic 

eduinfo
Starting Member

1 Post

Posted - 2002-01-05 : 13:56:04
Hi is there any way by which i can run the queeires ina text file programmatically

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-01-05 : 14:01:51
The osql command line utility was designed specifically to do this. It is documented fully in Books Online, but the general syntax is this (using the C:\mycode.sql file):

osql -i "C:\mycode.sql" -Uusername -Ppassword -Sservername

If you want the output of the query to go into a file, you can use the -o switch, but you might be better off using bcp for outputting data into a file, as it is more flexible.

Go to Top of Page
   

- Advertisement -