This post is a guide on how to export data from SQL Server into a CSV file, via SQL Server Management Studio (SSMS).
The default Export Settings in SSMS is set as Column Aligned. We need to change this to Comma Delimited first so it formats correctly.
Export SQL Server Query to CSV File
To export a query the simplest way, it would be for us to click Results to File as marked below.
When you run the query, it’ll prompt asking where and what to save the file as.
The default file type is as shown above, a .rpt file. If we open that in NotePad++, it’s looking like this;
We’ll save it as CSV this time.
You’ll probably want to change the delimiter after looking at the file.
Set Output File to Column Aligned
We’ll have to go into the options of SSMS as shown below.
Into Results to Text, we can see the output format is set to Column aligned.
We’ll change that default value to Comma delimited.
You’ll need to disconnect your current session within the Object Explorer and connect back to the SQL Server.
Now, if we run that query and check the output file;
Looking better now!