dbTalk Databases Forums  

bcp and embedded quoted fields

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss bcp and embedded quoted fields in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dash39
 
Posts: n/a

Default bcp and embedded quoted fields - 08-04-2009 , 01:21 PM






using sql server 2k, I have been importing csv files reliably for months but
have now been sent a new csv file which contains a quoted field that
contains a comma
e.g... , "abcd, efgh" , .... No previous files had any quoted fields.
bcp does not like this at all. I have searched but have not found how to
resolve this issue. Any comments or suggestions will be much appreciated.

Reply With Quote
  #2  
Old   
Linchi Shea
 
Posts: n/a

Default RE: bcp and embedded quoted fields - 08-04-2009 , 03:34 PM






BCP doesn't work well with the CSV format. The solution is to avoid feeding
it any data format that may confuse it. Choose a column separator that is
unique and not embedded, and aviod quoting the columns. In other words, the
most reliable way to use BCP is to have a step that validates the incoming
data and further processes it into a simple format before feeding the data to
BCP.

Linchi

"Dash39" wrote:

Quote:
using sql server 2k, I have been importing csv files reliably for months but
have now been sent a new csv file which contains a quoted field that
contains a comma
e.g... , "abcd, efgh" , .... No previous files had any quoted fields.
bcp does not like this at all. I have searched but have not found how to
resolve this issue. Any comments or suggestions will be much appreciated.

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: bcp and embedded quoted fields - 08-04-2009 , 04:19 PM



Dash39 (Dash39 (AT) discussions (DOT) microsoft.com) writes:
Quote:
using sql server 2k, I have been importing csv files reliably for months
but have now been sent a new csv file which contains a quoted field
that contains a comma e.g... , "abcd, efgh" , .... No previous files had
any quoted fields. bcp does not like this at all. I have searched but
have not found how to resolve this issue. Any comments or suggestions
will be much appreciated.
BCP can deal with quoted fields, but the quoting must be applied
consistently. If a field is quoted in one record, but not in the next,
you lose.

BCP works with a stream of bytes, handles both binary files and text files.
Or rather: text files are handled as any other binary file. To use quoted
fields, you need to define your delimiters with the quotes as part of them.
To this end you typically need to use a format file.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.