Export Records From SQL Server To Text File

The fastest way to export records from SQL Server table to a text file is to use BCP command.

Step 1
 
First step will be to enable XP_CMDSHELL.
Use Master
GO
EXEC master.dbo.sp_configure 'xp_cmdshell', 0
RECONFIGURE WITH OVERRIDE
GO
EXEC master.dbo.sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO

Query Output

Configuration option 'xp_cmdshell' changed from 1 to 0. Run the RECONFIGURE statement to install.
Configuration option 'show advanced options' changed from 1 to 0. Run the RECONFIGURE statement to install.

Step 2

Execute the following given query

EXEC xp_cmdshell 'bcp "SELECT ColumnName FROM [DataBaseName].[Schemas].[TableName]" queryout "C:\Temp\CountryRegion.txt" -T -c -t,'