dbTalk Databases Forums  

How to use bcp when dealing with commas and double quotes

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss How to use bcp when dealing with commas and double quotes in the microsoft.public.sqlserver.dts forum.



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

Default How to use bcp when dealing with commas and double quotes - 10-25-2004 , 12:41 PM






Hi,
If there a method to format the bcp out so that it handles both commas and
double quotes?
To explain:
I have the same problem with dts that I have with bcp. When I try to import
descriptions that contain either double quotes or commas, I receive a
SQLState = 22001 Sting data, right truncation. I could make the field larger
than the field that goes in by two characters, but if I have both a comma and
a double quote (inches), I'll need to increase the size of the field more.
It seems like that solution is poor because there is no way, short of
doubling the field size, that I can be sure it is adequate. I think adding
the -q option might work for the quotes???? But what will make the commas
import?

OUT Context:
C:\>bcp quoteupdate.dbo.vnewparts out c:\integrator\partslist.bcp -n -T

Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000

1498 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 2031
--
Quack,
I wouldn't be asking this if I were anything but...

Reply With Quote
  #2  
Old   
Quack
 
Posts: n/a

Default RE: How to use bcp when dealing with commas and double quotes - 10-25-2004 , 12:51 PM






Let me add the following:
In a post I found on this
(http://www.examnotes.net/archive79-2002-8-54521.html) there was a suggestion
to surround each field with double quotes, but there is also some very
strange syntax in the post which I do not understand. It does explain the
problem this Quack is having at the moment.
<snip>
Quote:
- Text Qualifier = Double Quote

bcp does not recognize text qualifiers. They are just
more characters as far as bcp is concerned. That is why
you are getting an error message because the fields in
the field including the quotes are too large for the
receiving columns.

If you want to keep the quotes you will need to use a format
file that looks like this:

8.0
9
1 SQLCHAR 0 1 "\"" 0 first_quote ""
2 SQLCHAR 0 10 "\"," 1 exceptionid ""
3 SQLCHAR 0 7 ",\"" 2 severity ""
4 SQLCHAR 0 1 "\"," 3 followupperiod ""
5 SQLCHAR 0 12 "," 4 followupqty ""
6 SQLCHAR 0 12 "," 5 leaddays ""
7 SQLCHAR 0 6 ",\"" 6 isactive ""
8 SQLCHAR 0 100 "\",\"" 7 followupattr ""
9 SQLCHAR 0 255 "\"\r\n" 8 description ""
<snip>


If the post actually has an answer for the Quack, the Quack can't tell
because the Quack has no idea what the above syntax refers to. It looks good
and feels like an answer but it doesn't help much.

Quack (duck not, quack for sure)

"Quack" wrote:

Quote:
Hi,
If there a method to format the bcp out so that it handles both commas and
double quotes?
To explain:
I have the same problem with dts that I have with bcp. When I try to import
descriptions that contain either double quotes or commas, I receive a
SQLState = 22001 Sting data, right truncation. I could make the field larger
than the field that goes in by two characters, but if I have both a comma and
a double quote (inches), I'll need to increase the size of the field more.
It seems like that solution is poor because there is no way, short of
doubling the field size, that I can be sure it is adequate. I think adding
the -q option might work for the quotes???? But what will make the commas
import?

OUT Context:
C:\>bcp quoteupdate.dbo.vnewparts out c:\integrator\partslist.bcp -n -T

Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000

1498 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 2031
--
Quack,
I wouldn't be asking this if I were anything but...

Reply With Quote
  #3  
Old   
Quack
 
Posts: n/a

Default Quacking again - 10-25-2004 , 03:35 PM



Maybe this is it?

This Quack has located the following information
http://msdn.microsoft.com/library/de...t_bcp_9yat.asp

The Quack

"Quack" wrote:

Quote:
Let me add the following:
In a post I found on this
(http://www.examnotes.net/archive79-2002-8-54521.html) there was a suggestion
to surround each field with double quotes, but there is also some very
strange syntax in the post which I do not understand. It does explain the
problem this Quack is having at the moment.
snip
- Text Qualifier = Double Quote


bcp does not recognize text qualifiers. They are just
more characters as far as bcp is concerned. That is why
you are getting an error message because the fields in
the field including the quotes are too large for the
receiving columns.

If you want to keep the quotes you will need to use a format
file that looks like this:

8.0
9
1 SQLCHAR 0 1 "\"" 0 first_quote ""
2 SQLCHAR 0 10 "\"," 1 exceptionid ""
3 SQLCHAR 0 7 ",\"" 2 severity ""
4 SQLCHAR 0 1 "\"," 3 followupperiod ""
5 SQLCHAR 0 12 "," 4 followupqty ""
6 SQLCHAR 0 12 "," 5 leaddays ""
7 SQLCHAR 0 6 ",\"" 6 isactive ""
8 SQLCHAR 0 100 "\",\"" 7 followupattr ""
9 SQLCHAR 0 255 "\"\r\n" 8 description ""
snip


If the post actually has an answer for the Quack, the Quack can't tell
because the Quack has no idea what the above syntax refers to. It looks good
and feels like an answer but it doesn't help much.

Quack (duck not, quack for sure)

"Quack" wrote:

Hi,
If there a method to format the bcp out so that it handles both commas and
double quotes?
To explain:
I have the same problem with dts that I have with bcp. When I try to import
descriptions that contain either double quotes or commas, I receive a
SQLState = 22001 Sting data, right truncation. I could make the field larger
than the field that goes in by two characters, but if I have both a comma and
a double quote (inches), I'll need to increase the size of the field more.
It seems like that solution is poor because there is no way, short of
doubling the field size, that I can be sure it is adequate. I think adding
the -q option might work for the quotes???? But what will make the commas
import?

OUT Context:
C:\>bcp quoteupdate.dbo.vnewparts out c:\integrator\partslist.bcp -n -T

Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000

1498 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 2031
--
Quack,
I wouldn't be asking this if I were anything but...

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.