This post is a quick guide on how to export data from SQL Server into a CSV file. The default export to settings will try save your query as a column aligned .rpt file, so I’ll cover that below while converting to CSV format.
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!