You can take a look here
https://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/
This article use Bulk Copy Program (BCP) to create CSV files. Although it is possible to create a CSV file using DTS or SSIS, using BCP is often simpler and more efficient.
I use master..sysobjects as an example table to extract.
Create a simple CSV file
The simplest way to copy data from a database table to file is to use the basic BCP command:
BCP master..sysobjects out c:\sysobjects.txt -c -t, -T –S
The basic format for the BCP command for creating a CSV file is as follows:
BCP out
The switches used here are:
-c Output in ASCII with the default field terminator (tab) and row terminator (crlf)
-t override the field terminator with ","
-T use a trusted connection. Note that U –P may be used for username/password
-S connect to this server to execute the command
Note that, like DTS/SSIS, BCP is a client utility, hence you need to supply the connection information.
For transfer of data between SQL servers, in place of –c, use –n or -N for native data format (-N = Unicode). This is much faster and avoids data conversion problems. Please refer to the previous BOL link for the complete format of the BCP command.
As BCP is a command line utility it is executed from T-SQL using xp_cmdshell. Create a directory called BCP on your c: drive and execute:
declare @sql varchar(8000)select @sql = 'bcp master..sysobjects out
c:\bcp\sysobjects.txt -c -t, -T -S'+ @@servernameexec master..xp_cmdshell @sql