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
 Transact-SQL (2000)
 Multiple SELECT statements in one script

Author  Topic 

obiwaugh
Starting Member

27 Posts

Posted - 2005-11-08 : 16:04:18
In SQL Plus for Oracle, I can execute a script in a text file....the text file contains about 20 different SELECT statements.

Can the same be done using SQL Server?

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

I know enough to know that I don't know enough.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-08 : 16:12:43
Yes, via osql.exe which is a command line utility.

Start..Run..cmd..<enter>

osql.exe -SServer1 -E -iC:\SomeScript.sql

Run osql /? to see its details or check SQL Server Books Online.

Tara Kizer
Go to Top of Page

obiwaugh
Starting Member

27 Posts

Posted - 2005-11-08 : 16:52:21
What can I put in the script so that the output spools to a text file?

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

I know enough to know that I don't know enough.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-08 : 16:59:28
osql.exe -SServer1 -E -iC:\SomeScript.sql -oC:\SomeOutputFile.txt

Or if you are going to be running multiple scripts wrapped in a cmd or batch file then:
osql.exe -SServer1 -E -iC:\SomeScript1.sql >C:\SomeOutputFile.txt
osql.exe -SServer1 -E -iC:\SomeScript2.sql >>C:\SomeOutputFile.txt

> says to create a new file
>> says to append

Tara Kizer
Go to Top of Page
   

- Advertisement -