Microsoft KB Archive/73182

= INFO: Using BCP When Data Is Within Quotation Marks =

Article ID: 73182

Article Last Modified on 2/14/2005

-

APPLIES TO


 * Microsoft SQL Server 4.21a Standard Edition

-



This article was previously published under Q73182



SUMMARY
This article describes how to customize the bulk copy program (BCP) format file to strip off unwanted quotation marks around the character strings in the data file.



MORE INFORMATION
It is possible to customize the BCP format file to strip off quotation marks that surround character strings in the user's ASCII data file. This process requires modifying the terminators to include a backslash+quotation mark (\&quot;) to interpret the quotation mark as a literal. If the first field in the data file is within quotation marks, you must add a new line to the BCP format file to dispose of the first quotation mark.

This example explains how to use BCP in the data file to exclude the quotation marks:

Data File
&quot;John&quot;,&quot;Doe&quot;,33,&quot;New York&quot;

&quot;Jane&quot;,&quot;Doe&quot;,31,&quot;Seattle&quot;

Format File
4.0 4 1   SYBCHAR   0    12   &quot;,&quot;       1    F_NAME 2   SYBCHAR   0    12   &quot;,&quot;       2    L_NAME 3   SYBCHAR   0    4    &quot;,&quot;       3    AGE 4   SYBCHAR   0    12   &quot;\r\n&quot;    4    BIRTH_PLACE

Perform the numbered steps below to modify the format file to remove the quotation marks:

  Increment the data field counter (line two of the format file) and the field number designators (numbers just below) by one. Then add a new first data description line to remove the first quotation mark:

     4.0 4+1     1    SYBCHAR   0    1    &quot;&quot;        0    FIRST_QUOTE <== NEW LINE 1+1 SYBCHAR   0    12   &quot;,&quot;       1    F_NAME 2+1 ...

  Next, modify the terminators to include quotation marks:

     Data           Terminator     Appearance in Format File --    --

abc&quot;,&quot;abc     &quot;,&quot;            &quot;\&quot;,\&quot;&quot; abc&quot;,123      &quot;,             &quot;\&quot;,&quot; 123,&quot;abc      ,&quot;             &quot;,\&quot;&quot; abc&quot;          &quot;         &quot;\&quot;\r\n&quot;



The final version of the BCP format file will resemble the following:

  4.0 5  1    SYBCHAR   0    1    &quot;&quot;        0    FIRST_QUOTE 2   SYBCHAR   0    12   &quot;\&quot;,\&quot;&quot;   1    F_NAME 3   SYBCHAR   0    12   &quot;\&quot;,&quot;     2    L_NAME 4   SYBCHAR   0    4    &quot;,\&quot;&quot;     3    AGE 5   SYBCHAR   0    12   &quot;\&quot;\r\n&quot;  4    BIRTH_PLACE

NOTE: The first line of the BCP.FMT refers to the version of the program. When running the version 1.1 or 1.11 of BCP this value is 4.0. In SQL Server 4.2 this value is 4.2.

For similar examples with Microsoft SQL Server version 4.21a, 6.0 and 6.5, please see the following article(s) in the Microsoft Knowledge Base:

132463 : INF: Using BCP When Data is in Quotation Marks

Additional query words: 4.20 quotes Windows NT

Keywords: kbinfo KB73182

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.