Re: Bcp problem (2005), previously posted to microsoft.public.sqlserver.programming



Mike C# (xyz@xxxxxxx) writes:
Having an issue with bcp on 2005, but brain is fried today for some
reason. Any help appreciated. Here's the deal:

I have an XML format file like this:

<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR="|" MAX_LENGTH="50"
COLLATION="Latin1_General_CI_AS"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR="|" MAX_LENGTH="10"
COLLATION="Latin1_General_CI_AS"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="ReportingDate" xsi:type="SQLVARYCHAR"/>
<COLUMN SOURCE="2" NAME="PolicyID" xsi:type="SQLVARYCHAR"/>
</ROW>

The source file looks like this:

2007-10-10|ABC123
2007-10-10|DEF456
...

This works great for a table with 2 columns (ReportingDate, PolicyID).
When I add an IDENTITY column, so the destination table looks like this
(for example):

ID INT IDENTITY(1, 1) NOT NULL,
ReportingDate VARCHAR(50),
PolicyID VARCHAR(50)

Bcp and BULK INSERT break when I try to use the format file with the new
IDENTITY column. I've gotten around this problem before, but I'll be
darned if I can remember how. It's probably really simple, but I'm a
little out of it this morning. If anyone has any hints, it's
appreciated.

If the IDENTITY column is the first in the table, you need to change COLUMN
SOURCE="1" to COLUMN SOURCE="2" etc. I never use the XML format file, but in
the old-style format file the colunm with the column names is informational
only. It's the column number that matters.


--
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

  • Re: BULK INSERT into table with identity column?
    ... INSERT into a temp table with an identity column. ... still has to be in the file if you don't use a format file. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Cannot fetch a row from OLE DB provider "BULK" for linked serv
    ... If I can remove all embedded commas in the ... then BULK INSERT and the format file (after removing ... I could create an XML file. ... Learning to use XML in SQL Server ...
    (microsoft.public.sqlserver.programming)
  • RE: BCP genric error
    ... I issue the bcp I get ... How does the format file look like? ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: bcp accent problem
    ... when I use a bcp format file it just stops working properly. ... Do you explicitly specify the ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: On to Bulk Insert issues
    ... in what situations does the sql server 2000 return with such an error? ... tell MS SQL Server that the fields are optionally enclosed by quotes. ... format file where you specify each field. ... row terminator is really only the terminator for the last field. ...
    (comp.databases.ms-sqlserver)