Check Export table from database to csv file answer here:
Using SQLCMD (Command Prompt):
From the command prompt, you can run the query and export it to a file:
sqlcmd -S . -d DatabaseName -E -s',' -W -Q "SELECT * FROM TableName" > C:\Test.csv
Notes:
This approach will have the "Rows affected" information in the bottom of the file, but you can get rid of this by using the "SET NOCOUNT ON" in the query itself.
You may run a stored procedure instead of the actual query (e.g. "EXEC Database.dbo.StoredProcedure")
You can use any programming language or even a batch file to automate this
Using ApexSQL tool:
Export SQL Server data to CSV by using the ApexSQL Complete Copy results as CSV option.
The Copy code as is a feature in ApexSQL Complete, a free add-in for SSMS and Visual Studio, that copy the data from the Results grid to a clipboard in one of the following data files: CSV, XML, HTML in just one click.
In a query editor, type the following code and execute:
Example:
USE AdventureWorks2014
SELECT at.* FROM Person.AddressType at
In the Results grid, select the part or all data, right click and from the context menu, under the Copy results as sub-menu, choose the commands like CSV, XML & HTML
This will copy the selected data from the Results grid to the clipboard. Now, all that needs to be done is to create a file where the copied data should be pasted:
The ApexSQL Complete Copy code as an option can save you a great amount of time when you need to copy repetitive SQL data to another data format.