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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server query to a CSV file

Status
Not open for further replies.

orbitkgf

Programmer
Sep 5, 2000
3
US
I imagine that this isn't too difficult, but I've never actually written to a CSV file before.

I have experience with PL/SQL for Oracle, but not for MS SQL Server.

All I need to do is select several rows from several different tables, with a few conditions, then write that info. to a CSV file. Can somebody help with this, please!!!?

Example table = class_type
class_type_num class_type_desc
1 Broker
2 Shareholder
3 Other

Select class_type_desc from class_type where class_type_num = 1 or class_type_num = 2

Output file would be:
Broker, Shareholder
 
I think the simplest and easiest way would be with the DTS Export Wizard. For details, including descriptions of the various options such as field delimiters, see the Books Online topic: DTS, exporting data.
 
Another way in Query Analyzer is:
goto query menu, current connection options
then advanced and change result output format to CSV.

Now when you run your query you can click in the result pane and save the file.

I find this handy for saving adhoc SQL query outputs to file

 
Thank you very much for the replies, but I guess I forgot to mention one thing in the original question.

The user would like to be able to do an adhoc query from a webpage. He would like to be able to select fields, then click submit, and get a CSV file. So, what I really need to know is how to do this with ASP.

Any help would be greatly appreciated. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top