0

In SQL Server 2000, I need to convert a table data (whole, not partial) to a text file (csv or tab).

How can I do this with a table (tblCustomer) which has name, address, phone number, for example?

I don't use SQL Server Management Studio. I have many groups of stored procedures running on daily basis and just want to write a stored procedure to add in to one of the groups.

user1364865
  • 21
  • 1
  • 5

2 Answers2

0

Are you using SQL Server Management Studio?

If so, just right click on the database name, and choose tasks->export data from the context menu, then follow the wizard.

paul
  • 21,653
  • 1
  • 53
  • 54
0

You you are using Management studio, you can try this:

  1. In your SQL Server Management Studio, right-click on the database where the table is and select Tasks->Export Data. This will bring up the SQL Server Import and Export Wizard, which is very much similar to the DTS Import/Export utility of SQL Server 2000.
  2. Select your table from the "Choose a Data Source" screen then click on Next.
  3. In the "Choose a Destination", select "Flat File Destination" as your Destination and enter the File name.

Just click on Next after that and you should be ok already.

You can also export it to xml using a query and then, on your app, convert it do csv. Check this out: FOR XML

Or, as @Aaron said, use The BCP Utility

EDIT

As you said you want the query way, I would go for the For XML and them parse the result to a CSV format. AFAIK, SQL server does not have an way of doing what you want automatically, so you will have to make it yourself. Also, you can adapt this sample.

Here and here you can find some scripts that may help you.

Community
  • 1
  • 1
Rafael Colucci
  • 6,018
  • 4
  • 52
  • 121
  • I don't use SQL Server Management Studio. I have many groups of stored procedures running on daily basis and just want to write a stored procedure to add in to one of the groups. – user1364865 Oct 29 '12 at 15:38