我有一个固定长度的文本文件,我需要在sql-server-2008上导入我的表。
我正在使用此脚本上传文件:
insert into imsdata
select *
from openrowset (bulk 'e:\imsdata.txt',
formatfile='e:\myformatfile.xml'
) as t1;
导入正在进行;但是,它无法正常工作。
以下是格式文件的样子:
<?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="1" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="2" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="3" xsi:type="NativeFixed" LENGTH="16"/>
<FIELD ID="4" xsi:type="NativeFixed" LENGTH="12"/>
<FIELD ID="5" xsi:type="NativeFixed" LENGTH="16"/>
<FIELD ID="6" xsi:type="NativeFixed" LENGTH="8"/>
<FIELD ID="7" xsi:type="NativeFixed" LENGTH="15"/>
<FIELD ID="8" xsi:type="NativeFixed" LENGTH="25"/>
<FIELD ID="9" xsi:type="NativeFixed" LENGTH="20"/>
<FIELD ID="10" xsi:type="NativeFixed" LENGTH="25"/>
<FIELD ID="11" xsi:type="NativeFixed" LENGTH="5"/>
<FIELD ID="12" xsi:type="NativeFixed" LENGTH="3"/>
<FIELD ID="13" xsi:type="NativeFixed" LENGTH="3"/>
<FIELD ID="14" xsi:type="NativeFixed" LENGTH="3"/>
<FIELD ID="15" xsi:type="NativeFixed" LENGTH="12"/>
<FIELD ID="16" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="17" xsi:type="NativeFixed" LENGTH="15"/>
<FIELD ID="18" xsi:type="NativeFixed" LENGTH="30"/>
<FIELD ID="19" xsi:type="NativeFixed" LENGTH="15"/>
<FIELD ID="20" xsi:type="NativeFixed" LENGTH="4"/>
<FIELD ID="21" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="22" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="23" xsi:type="NativeFixed" LENGTH="1"/>
<FIELD ID="24" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="25" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="26" xsi:type="NativeFixed" LENGTH="20"/>
<FIELD ID="27" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="28" xsi:type="NativeFixed" LENGTH="4"/>
<FIELD ID="29" xsi:type="NativeFixed" LENGTH="100"/>
<FIELD ID="30" xsi:type="NativeFixed" LENGTH="20"/>
<FIELD ID="31" xsi:type="NativeFixed" LENGTH="12"/>
<FIELD ID="32" xsi:type="NativeFixed" LENGTH="2"/>
<FIELD ID="33" xsi:type="NativeFixed" LENGTH="1"/>
<FIELD ID="34" xsi:type="NativeFixed" LENGTH="50"/>
<FIELD ID="35" xsi:type="NativeFixed" LENGTH="50"/>
<FIELD ID="36" xsi:type="NativeFixed" LENGTH="50"/>
<FIELD ID="37" xsi:type="NativeFixed" LENGTH="50"/>
<FIELD ID="38" xsi:type="NativeFixed" LENGTH="30"/>
<FIELD ID="39" xsi:type="NativeFixed" LENGTH="15"/>
<FIELD ID="40" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="41" xsi:type="NativeFixed" LENGTH="20"/>
<FIELD ID="42" xsi:type="NativeFixed" LENGTH="9"/>
<FIELD ID="43" xsi:type="NativeFixed" LENGTH="7"/>
<FIELD ID="44" xsi:type="NativeFixed" LENGTH="3"/>
<FIELD ID="45" xsi:type="NativeFixed" LENGTH="1"/>
<FIELD ID="46" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="47" xsi:type="NativeFixed" LENGTH="1"/>
<FIELD ID="48" xsi:type="NativeFixed" LENGTH="15"/>
<FIELD ID="49" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="50" xsi:type="NativeFixed" LENGTH="5"/>
<FIELD ID="51" xsi:type="NativeFixed" LENGTH="20"/>
<FIELD ID="52" xsi:type="NativeFixed" LENGTH="5"/>
<FIELD ID="53" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="54" xsi:type="NativeFixed" LENGTH="5"/>
<FIELD ID="55" xsi:type="NativeFixed" LENGTH="10"/>
<FIELD ID="56" xsi:type="NativeFixed" LENGTH="46"/>
<FIELD ID="57" xsi:type="CharTerm" TERMINATOR="\r\n" />
</RECORD>
<ROW><COLUMN SOURCE="1" NAME="TransactionCode" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="2" NAME="TransmissionDate" xsi:type="SQLDATE" LENGTH="10" />
<COLUMN SOURCE="3" NAME="ProfAcctID" xsi:type="SQLCHAR" LENGTH="16"/>
<COLUMN SOURCE="4" NAME="TerritoryID" xsi:type="SQLCHAR" LENGTH="12"/>
<COLUMN SOURCE="5" NAME="OrgID" xsi:type="SQLCHAR" LENGTH="16"/>
<COLUMN SOURCE="6" NAME="UserID" xsi:type="SQLCHAR" LENGTH="8"/>
<COLUMN SOURCE="7" NAME="Prefix" xsi:type="SQLCHAR" LENGTH="15"/>
<COLUMN SOURCE="8" NAME="FirstName" xsi:type="SQLCHAR" LENGTH="25"/>
<COLUMN SOURCE="9" NAME="MiddleName" xsi:type="SQLCHAR" LENGTH="20"/>
<COLUMN SOURCE="10" NAME="LastName" xsi:type="SQLCHAR" LENGTH="25"/>
<COLUMN SOURCE="11" NAME="Suffix" xsi:type="SQLCHAR" LENGTH="5"/>
<COLUMN SOURCE="12" NAME="SpecialtyPrimaryCode" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="13" NAME="SpecialtySecondaryCode" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="14" NAME="SpecialtyTertiaryCode" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="15" NAME="ProfessionalID1" xsi:type="SQLCHAR" LENGTH="12"/>
<COLUMN SOURCE="16" NAME="ProfessionalID1Source" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="17" NAME="CertificationCode" xsi:type="SQLCHAR" LENGTH="15"/>
<COLUMN SOURCE="18" NAME="AcctSubType" xsi:type="SQLCHAR" LENGTH="30"/>
<COLUMN SOURCE="19" NAME="ProfSubType" xsi:type="SQLCHAR" LENGTH="15"/>
<COLUMN SOURCE="20" NAME="BirthYear" xsi:type="SQLCHAR"/>
<COLUMN SOURCE="21" NAME="BirthMonth" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="22" NAME="BirthDay" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="23" NAME="Gender" xsi:type="SQLCHAR" LENGTH="1"/>
<COLUMN SOURCE="24" NAME="LastCallDate" xsi:type="SQLDATE"/>
<COLUMN SOURCE="25" NAME="Status" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="26" NAME="StateLicenseNumber" xsi:type="SQLCHAR" LENGTH="20"/>
<COLUMN SOURCE="27" NAME="StateLicenseNumberExp" xsi:type="SQLDATE"/>
<COLUMN SOURCE="28" NAME="ActualYTDCalls" xsi:type="SQLCHAR" LENGTH="4"/>
<COLUMN SOURCE="29" NAME="Email" xsi:type="SQLCHAR" LENGTH="100"/>
<COLUMN SOURCE="30" NAME="FaxNumber" xsi:type="SQLCHAR" LENGTH="20"/>
<COLUMN SOURCE="31" NAME="ProfessionalID2" xsi:type="SQLCHAR" LENGTH="12"/>
<COLUMN SOURCE="32" NAME="ProfessionalID2Source" xsi:type="SQLCHAR" LENGTH="2"/>
<COLUMN SOURCE="33" NAME="CallLocationTypeCode" xsi:type="SQLCHAR" LENGTH="1"/>
<COLUMN SOURCE="34" NAME="Address1" xsi:type="SQLCHAR" LENGTH="50"/>
<COLUMN SOURCE="35" NAME="Address2" xsi:type="SQLCHAR" LENGTH="50"/>
<COLUMN SOURCE="36" NAME="Address3" xsi:type="SQLCHAR" LENGTH="50"/>
<COLUMN SOURCE="37" NAME="Address4" xsi:type="SQLCHAR" LENGTH="50"/>
<COLUMN SOURCE="38" NAME="City" xsi:type="SQLCHAR" LENGTH="30"/>
<COLUMN SOURCE="39" NAME="StateorProvinceCode" xsi:type="SQLCHAR" LENGTH="15"/>
<COLUMN SOURCE="40" NAME="ZipCodeorPostalCode" xsi:type="SQLCHAR" LENGTH="10"/>
<COLUMN SOURCE="41" NAME="PhoneNumber" xsi:type="SQLCHAR" LENGTH="20"/>
<COLUMN SOURCE="42" NAME="DEANumber" xsi:type="SQLCHAR" LENGTH="9"/>
<COLUMN SOURCE="43" NAME="IMSPrescriberID" xsi:type="SQLCHAR" LENGTH="7"/>
<COLUMN SOURCE="44" NAME="IMSLocation" xsi:type="SQLCHAR" LENGTH="3"/>
<COLUMN SOURCE="45" NAME="DEAStateLicenseValidation" xsi:type="SQLCHAR" LENGTH="1"/>
<COLUMN SOURCE="46" NAME="Client" xsi:type="SQLCHAR" LENGTH="10"/>
<COLUMN SOURCE="47" NAME="TransactionType" xsi:type="SQLCHAR" LENGTH="1"/>
<COLUMN SOURCE="48" NAME="Service" xsi:type="SQLCHAR" LENGTH="15"/>
<COLUMN SOURCE="49" NAME="DEAExpirationDate" xsi:type="SQLCHAR" LENGTH="10"/>
<COLUMN SOURCE="50" NAME="PrescriberStatus" xsi:type="SQLCHAR" LENGTH="5"/>
<COLUMN SOURCE="51" NAME="DEAScheduleClass" xsi:type="SQLCHAR" LENGTH="20"/>
<COLUMN SOURCE="52" NAME="DEAAuthorizationStatus" xsi:type="SQLCHAR" LENGTH="5"/>
<COLUMN SOURCE="53" NAME="DEAAuthorizationStatusDate" xsi:type="SQLCHAR" LENGTH="10"/>
<COLUMN SOURCE="54" NAME="StateLicenseAuthorizationStatusCode" xsi:type="SQLCHAR" LENGTH="5"/>
<COLUMN SOURCE="55" NAME="StateLicenseAuthorizationStatusDate" xsi:type="SQLCHAR" LENGTH="10"/>
<COLUMN SOURCE="56" NAME="Expansion" xsi:type="SQLCHAR" LENGTH="46"/>
</ROW>
</BCPFORMAT>
我显然对格式文件做错了,因为当导入数据时,它会转移到右边。
问题:
如果我想导入固定长度(固定列长)的文本文件,xml格式文件应该是什么样的?