Jim
2008-02-28 15:29:04 UTC
Good morning,
I am receiving a fixed width flat file from a vendor. I am needing to
bulk import it into a SQL 2005 table. My problem is that my table
starts with some tracking fields that are not part of the vendor
file. I need to skip those fields when I import the data. But for
some reason, the server is not skipping the fields. I have read
everything I could in the BOL, and googled myself to death. I am
including a some sample codes that reproduce the problem. If anyone
could give any ideas, I would greatly appreciate it.
Thank you
Jim
CREATE TABLE:
CREATE TABLE [dbo].[ImportTest](
[ImportID] [int] IDENTITY(1,1) NOT NULL, -- mine
[LoadID] [int] NULL, -- mine, to be
filled in later
[AdminKey] [varchar](9) NULL, -- from import
[CustomerKey] [varchar](9) NULL, -- from import
[TransactionType] [varchar](1) NULL, -- from import
[SubscriberID] [varchar](36) NULL, -- from import
PRIMARY KEY CLUSTERED -- this is from the table I have in
production,
-- I have no idea if
it's needed or the cause of my problem
(
[ImportID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON [PRIMARY]
) ON [PRIMARY]
DATA.TXT:
000000001000000002Aa1b2c3d4e5f6g7h8i9j0klmnopqrstuvwxyz
Import_Format.XML:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/
format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="F1" xsi:type="CharFixed" LENGTH="9"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F2" xsi:type="CharFixed" LENGTH="9"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F3" xsi:type="CharFixed" LENGTH="1"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F4" xsi:type="CharFixed" LENGTH="36"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F5" xsi:type="CharTerm" TERMINATOR="\r\n"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
</RECORD>
<ROW>
<COLUMN SOURCE="F1" NAME="AdminPartyKey" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F2" NAME="CustomerPartyKey" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F3" NAME="TransactionType" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F4" NAME="SubscriberID" xsi:type="SQLCHAR" />
</ROW>
</BCPFORMAT>
BULK INSERT STATEMENT:
BULK INSERT ImportTest
FROM '\\lousqlwts04\FTPROOT\ADSCDS\ACSFiles\data.txt'
WITH (FORMATFILE = '\\lousqlwts04\FTPROOT\ADSCDS\Settings
\Import_Format.XML',
DATAFILETYPE = 'char'
);
What I Expect:
ImportID, LoadID,AdminKey , CustomerKey,TransactionType,SubscriberID
1 NULL 000000000 000000000 A
a1b2c3d4e5f6g7h8i9j0klmnopqrstuvwxyz
What I Get:
ImportID, LoadID,AdminKey , CustomerKey,TransactionType,SubscriberID
1 0 A a1b2c3d4e
I am receiving a fixed width flat file from a vendor. I am needing to
bulk import it into a SQL 2005 table. My problem is that my table
starts with some tracking fields that are not part of the vendor
file. I need to skip those fields when I import the data. But for
some reason, the server is not skipping the fields. I have read
everything I could in the BOL, and googled myself to death. I am
including a some sample codes that reproduce the problem. If anyone
could give any ideas, I would greatly appreciate it.
Thank you
Jim
CREATE TABLE:
CREATE TABLE [dbo].[ImportTest](
[ImportID] [int] IDENTITY(1,1) NOT NULL, -- mine
[LoadID] [int] NULL, -- mine, to be
filled in later
[AdminKey] [varchar](9) NULL, -- from import
[CustomerKey] [varchar](9) NULL, -- from import
[TransactionType] [varchar](1) NULL, -- from import
[SubscriberID] [varchar](36) NULL, -- from import
PRIMARY KEY CLUSTERED -- this is from the table I have in
production,
-- I have no idea if
it's needed or the cause of my problem
(
[ImportID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90)
ON [PRIMARY]
) ON [PRIMARY]
DATA.TXT:
000000001000000002Aa1b2c3d4e5f6g7h8i9j0klmnopqrstuvwxyz
Import_Format.XML:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/
format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="F1" xsi:type="CharFixed" LENGTH="9"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F2" xsi:type="CharFixed" LENGTH="9"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F3" xsi:type="CharFixed" LENGTH="1"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F4" xsi:type="CharFixed" LENGTH="36"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
<FIELD ID="F5" xsi:type="CharTerm" TERMINATOR="\r\n"
COLLATION="SQL_Latin1_General_CP1_CI_AS" />
</RECORD>
<ROW>
<COLUMN SOURCE="F1" NAME="AdminPartyKey" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F2" NAME="CustomerPartyKey" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F3" NAME="TransactionType" xsi:type="SQLCHAR" />
<COLUMN SOURCE="F4" NAME="SubscriberID" xsi:type="SQLCHAR" />
</ROW>
</BCPFORMAT>
BULK INSERT STATEMENT:
BULK INSERT ImportTest
FROM '\\lousqlwts04\FTPROOT\ADSCDS\ACSFiles\data.txt'
WITH (FORMATFILE = '\\lousqlwts04\FTPROOT\ADSCDS\Settings
\Import_Format.XML',
DATAFILETYPE = 'char'
);
What I Expect:
ImportID, LoadID,AdminKey , CustomerKey,TransactionType,SubscriberID
1 NULL 000000000 000000000 A
a1b2c3d4e5f6g7h8i9j0klmnopqrstuvwxyz
What I Get:
ImportID, LoadID,AdminKey , CustomerKey,TransactionType,SubscriberID
1 0 A a1b2c3d4e