How To Export SQL Server Table to CSV File

 

We usually export a dataset in SQL Server to Excel instead of CSV. But in some cases we may need to export to csv files. You can use the following articles to transfer data from Excel to SQL Server and from SQL Server to Excel.

How To Import Excel To SQL Server Table“,

How To Export SQL Server Table To Excel

Example:

Right-click on the database and click “Tasks->Export Data”.

On the incoming screen, select “Do not show this starting page again” and click next.

As soon as we select the “Microsoft OLE DB Provider for SQL Server or SQL Server Native Client” from the Data source section, the name of the Instance appears in the “ServerName” section and the database name appears in “Database:” section. Because we have clicked export by right-clicking on the database.

We’re moving forward by clicking Next.

In the incoming screen, select “Flat File Destination” from Destination.

In the “File name:” section, we click Browse, and go to the folder we want to export the file to. Then give a name to the file and add the .csv extension to the end of the name.

We select Turkish (Turkey) from the Locale section and proceed next. You should choose “Locale” and “Code page” according to your language.

While the “Copy data from one or more tables or views” is selected in the incoming screen, click next to proceed.

In the incoming screen, we select the table we want to export from “Source table or view:”. We will then specify a separator for the rows and columns as follows.

If we specify a CR (carriage return) in the row delimiter section, it creates a new line in the csv file for each row.

For Column delimiter, I usually choose Comma {,}.

Sometimes only {CR} is not enough for Row delimiter. To make it easy to transfer the file with the .csv extension to another system with code, add “||” in front of {CR} as follows.

Click Next to proceed. On the next screen, select “Run Immediately”.

Finally, click next and finish to complete the process.

dbtut
Author: dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *