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
 General SQL Server Forums
 New to SQL Server Programming
 Spool to a text file?

Author  Topic 

charliebrown
Starting Member

4 Posts

Posted - 2013-02-08 : 08:18:55
Hello, I am a real noob at SQL programming and was wondering if someone could tell me how it would be possible for me to have my sql script output to a txt file?

For example the sql script file I have saved is select * from abc.def:

1. How can I automate the output to a txt file?
2. How can I run the script from a command line since I am doing this now from SSMS.

Thank you!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-02-08 : 08:20:18
Read about BCP in SQL Server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-08 : 09:07:07
you've multiple options

1. bcp
2. OPENROWSET
3. SSIS export import

1 and 3 (using dtexec) can be executed from command line


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

charliebrown
Starting Member

4 Posts

Posted - 2013-02-08 : 09:13:06
I took a look at bcp and wow that looks pretty hard.
Go to Top of Page
   

- Advertisement -