Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output File 1

Status
Not open for further replies.

dimplekv

Programmer
May 21, 2001
7
US
How can I write my result from 'select * from abc' to a text file on C drive with the name 'Result_061301.txt' where 6/13/01 is the system date?

Any Ideas?
 
Good question? Are you doing this from an application development perspective or running it from query analyzer. If it is from query analyzer you can just save the results of your query as a csv or txt file when you run the query (click in the results pane and click File, Save).

From an application development point of view use the client (which could be vb, c or some program) to control output.
 
You could use DTS to create the export package but I haven't ever been able to set a dynamic output filename. Instead, using SQL2000, you can save your DTS package as a VB file and edit SQL's generated VB code to concatenate the date to the file name. You can then execute the export from VB.
Note: You need to reference Microsoft DTSPackage Object Library
 
No way exists to directly pipe a query's output from a stored procedure or Query Analyzer into a text file. In addition to DTS, you can use command line utilities, BCP, ISQL and OSQL to output to a text file.

You can do many things in a query or stored procedure including dynamic creation of file names. There are several ways to indirectly output text from T-SQL. If you want to output to text from a query or stored procedure check the info at Terry

The reason why worry kills more people than work is that more people worry than work. - Robert Frost
 
Thanks for your response guys.
I will be running the SQL command using Osql/isql to get the output. I cannot use VB as we don't have it.
I am surprised that this feature is not available in MS SQL Server. I think many of us are using this with a work around.
Thanks anyway.
 
You can create your own extended stored procedure, let's say xp_writer file and call it from your SP.

VC++ Enterprise Edition has a wizard for sxtended SPs which is easy to use.Then use sp_addextendedproc to add your extended SP to the available XPs.
(I had made something similar two years ago but
unfortunately I don't have the code to show you. But it works, this I can tell you)


Good luck,s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top