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)
 Write results of a query to a file?

Author  Topic 

kam
Starting Member

17 Posts

Posted - 2006-03-01 : 18:07:30
Hi, Im trying to write the results of a query in a SP to a text file.
Can someone direct me on how I would achieve this?

Many Thanks in Advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-01 : 18:20:22
You can do this with DTS or bcp.exe.

Tara Kizer
aka tduggan
Go to Top of Page

kam
Starting Member

17 Posts

Posted - 2006-03-01 : 18:43:10
I've tried a google serahc for both terms which came back alot of results, all of which seemed beyong the scope of what I'm trying to achieve. Could you possibly suggest a site/provide sample code.

Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-03-01 : 18:46:12
SQL Server Books Online is the help documentation for SQL Server. If you installed the client tools, then you've got BOL.

bcp.exe is command line utility to import/export data from a table/view or a query.

DTS is similar but it is a GUI tool from within Enterprise Manager. If this is a one-time thing, I'd suggest going to the import/export wizard, specify a query for the source, and a file for the destination. If this is for an on-going thing, then you'll need to design a package using the DTS designer.

www.sqldts.com has a lot of great articles on DTS.

Tara Kizer
aka tduggan
Go to Top of Page

p.shaw3@ukonline.co.uk
Posting Yak Master

103 Posts

Posted - 2006-03-02 : 08:17:31
If a Spreadsheet will do then you can accomplish this in Query Analyser. Go to 'Tools'-'Options' click on the 'Results' tab and change to 'Results to Text'. Then run your query, define where you want your Spreadsheet to be saved and that's it.

Pat.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-03-02 : 08:20:45
Note that Query Analyser has a restriction on the output width of a column. If you have text data columns with more than 8,000 characters you are out of luck. By default Query Analyser shows a Max of 255 characters per column, but you can increase that (up to 8000) in the Options.

Kristen
Go to Top of Page
   

- Advertisement -