views:

188

answers:

2

SQL Server 2005 - How can I save the results of a query to a text file programatically? (i.e without choosing the Results to file option in Analyzer and not through sql command)?

For example

select * from northwind.dbo.suppliers

And I save my results to CSV file?

A: 

in language of your choice

Open a SQL Connection
Issue command (select)
While not end_of_results
  for each column
    write column value
    write ','
  write new line
Clean up connection
Preet Sangha
+3  A: 

this will show you how: Creating CSV Files Using BCP and Stored Procedures

or this: How do I send a database query to a text file?

KM