Re: Bulk Insert



(robpatt@xxxxxxxxx) writes:
The file I am attempting to bulk insert has " " around all the text
fields, Bulk Insert is trying to insert the double quotes with the
text, and the error message says:

Error: Bulk Insert fails. Column is too long in the data file for row
1, column 1. Make sure the field terminator and row terminator are
specified correctly. (State:37000, Native Code: 1302)

As any other tool, BULK INSERT does what you tells it to. If you say
that you have a text file with comma as field delimiter, that means a
file with comma as field delimiter, and quotes are obviously not part
of the text.

If the format is something like this:

"a field","another field","next field",2,2

you need to use a format file. A format file for the above would look
like, assuming that field order in file agress with column order:

8.0
6
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\",\"" 1 col1 ""
3 SQLCHAR 0 0 "\",\"" 2 col2 ""
4 SQLCHAR 0 0 "\"," 3 col3 ""
5 SQLCHAR 0 0 "," 4 col4 ""
6 SQLCHAR 0 0 "\r\n" 5 col5

If the first field is not quoted, you should skip that first line, which
defines an empty dummy field, to get the first quote out of the way.

Note that the column names in the file does not matter, it's the column
numbers that count, and 0 means that that field is not imported.

If you want to know more gory details, search for posts from me and BCP
or "format file" in the text on Google news.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Bulk Insert for data with quotes
    ... Format file ... >I am new to DTS, I use bulk insert to load a csv file ... >character data in double quotes. ... But the bulk insert ...
    (microsoft.public.sqlserver.dts)
  • RE: Bulk Insert for data with quotes
    ... I have tried the format file and given the double quotes as the text ... Can it be used in Bulk inserts? ...
    (microsoft.public.sqlserver.dts)
  • Re: Bulk Insert & Text Qualifier
    ... Here is an example of a format file to remove the quotes. ... > How can I specify a text qualifier on Bulk Insert? ... > When I Bulk Insert texts like "NY", the quotes are imported as well. ...
    (microsoft.public.sqlserver.programming)
  • Re: Bulk Insert for data with quotes
    ... No you cannot use REPLACE in the BULK INSERT. ... Allan Mitchell MCSE,MCDBA, www.SQLDTS.com - The site for all your DTS needs. ... I have tried the format file and given the double quotes as the text> qulaifier but it still doesnt work. ...
    (microsoft.public.sqlserver.dts)
  • Re: Bulk Insert Question
    ... >>I need to move some data from an ascii file to a database. ... The problem I have is there is no field seperation in the ... Is there a way to use BULK INSERT without having to put ... > editor to check the contents of the format file and tweak it as needed. ...
    (microsoft.public.sqlserver.programming)