Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Quotes around data exported in bcp command

Author  Topic 

robert693
Starting Member

42 Posts

Posted - 2010-11-16 : 08:36:59
Hello,

I am exporting out of a SQL database into a CSV file. I forgot to mention in a earlier post that this export is done with a bcp command. I would like to put double quotes around the data. In the bcp command, I have tried -t"," but this does not work. I cannot put the quotes right into the query because that does not seem to work. I was wondering what I can do. Thank you for all of your help!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-16 : 10:22:44
bcp "SELECT char(34) + col1 + char(34), char(34)+ col2 + char(34)...
Go to Top of Page

robert693
Starting Member

42 Posts

Posted - 2010-11-16 : 13:10:40
Thank you! That worked.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-11-16 : 14:05:41
You might need

bcp "SELECT char(34) + REPLACE(col1, '"', '""') + char(34), char(34)+ REPLACE(col2, '"', '""') + char(34)...

if your columns may contains " characters. Might be easier to use a User-Defined-Function to wrap with quotes and encode any embedded quotes?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-16 : 16:42:13
You're welcome
Go to Top of Page
   

- Advertisement -