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
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...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.