BCP with Double Quotes for OUTPUT File


 
 ----bcp OUT  with double quote around text type columns and ignore number columns
exec master..xp_cmdshell  'bcp "select  id, char(34)+col1+char(34), char(34)+col2+char(34), char(34)+col3+char(34) from  [yourDB].[dbo].[yourtable]" QUERYOUT "C:\temp\yourFile.txt"   -T -c -t, -b 100 -S serverName\DBInstance';

go

 

I have to add to this if you can use SSIS package (Simply Import/Export Wizard from SSMS). You can simply add a Text Qualifier through flat file connection setting with a double quote when you export your table to a CSV file. That is simple.

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s