2011-01-21 81 views
2

我无法使用BCP将制表符分隔的* .txt文件中的数据导入到我的SQL表中。BCP导入帮助

我不断收到两个“无效的字符值铸造规范”错误。

作为测试,我手动插入了几行。然后我BCP将这些行查询到一个* .txt文件。然后我尝试BCP导入相同的数据。

随着该测试中,我得到了错误和一个“流延规范无效字符值”

有没有办法告诉哪些行/列触发错误“意外的EOF BCP数据文件中遇到”?

调试BCP的任何提示/建议?

#@ Row 1, Column 2: Invalid character value for cast specification @# 
1003 1/2/2011 23:59:00 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US 2222222222 [email protected] <NULL> UPS GRD 42.650 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Seal Style = , Attachment = NONE, Text Separator = NONE, Badge Comments = , badgeURL = http://www.blackinton.com/design-a-badge/data/pdf/vhbdab1291672350948.png, RESTXML = http://www.blackinton.com/design-a-badge/generate-xml.php?u=vhbdab1291672350948, Base Price = 59.00, Enamel = 0.00, Struck Solid = 0.00, Seal = 0.0 3271.8700 0.0000 0.0000 0.0000 3271.8700 1 Visa <NULL> 0 
1004 1/3/2011 23:59:00 Neeta Garg <NULL> 8888   WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg  8888   WESTBURY NY 11594 US 2222222222 [email protected]  UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Sea 
#@ Row 2, Column 2: Invalid character value for cast specification @# 
1005 1/4/2011 23:59:00 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US 2222222222 [email protected] <NULL> UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Seal Style = , Attachment = NONE, Text Separator = NONE, Badge Comments = , badgeURL = http://www.blackinton.com/design-a-badge/data/pdf/vhbdab1291672350948.png, RESTXML = http://www.blackinton.com/design-a-badge/generate-xml.php?u=vhbdab1291672350948, Base Price = 59.00, Enamel = 0.00, Struck Solid = 0.00, Seal = 0.0 115.9900 8.0000 0.0000 0.0000 123.9900 1 Visa <NULL> 0 
1006 2011-01-05 11:27:50.617 Neeta Garg <NULL> 8888   WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg  8888   WESTBURY NY 11594 US 2222222222 [email protected]  UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1A161BK;115.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 

我想通了,你不能将BCP导入日期作为日期时间类型。所以,我将它导入临时表,其中类型是varchar,然后我将SELECT INTO到我想要的表中。但是,即使使用目标表的列类型varchar,我也会得到无效的字符错误。

#@ Row 1, Column 2: Invalid character value for cast specification @# 
1003 2011-01-21 12:30:10.917 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US 2222222222 [email protected] <NULL> UPS GRD 42.650 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Seal Style = , Attachment = NONE, Text Separator = NONE, Badge Comments = , badgeURL = http://www.blackinton.com/design-a-badge/data/pdf/vhbdab1291672350948.png, RESTXML = http://www.blackinton.com/design-a-badge/generate-xml.php?u=vhbdab1291672350948, Base Price = 59.00, Enamel = 0.00, Struck Solid = 0.00, Seal = 0.0 3271.8700 0.0000 0.0000 0.0000 3271.8700 1 Visa <NULL> 0 
1004 2011-01-21 12:30:10.917 Neeta Garg <NULL> 8888   WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg  8888   WESTBURY NY 11594 US 2222222222 [email protected]  UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Sea 
#@ Row 2, Column 2: Invalid character value for cast specification @# 
1005 2011-01-21 12:30:10.917 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg <NULL> 8888 <NULL> <NULL> WESTBURY NY 11594 US 2222222222 [email protected] <NULL> UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 3 = , Panel 5 = , Panel 6 = , Seal Style = , Attachment = NONE, Text Separator = NONE, Badge Comments = , badgeURL = http://www.blackinton.com/design-a-badge/data/pdf/vhbdab1291672350948.png, RESTXML = http://www.blackinton.com/design-a-badge/generate-xml.php?u=vhbdab1291672350948, Base Price = 59.00, Enamel = 0.00, Struck Solid = 0.00, Seal = 0.0 115.9900 8.0000 0.0000 0.0000 123.9900 1 Visa <NULL> 0 
1006 2011-01-21 12:30:10.917 Neeta Garg <NULL> 8888   WESTBURY NY 11594 US ambulance Yes Agency 92240099 000026 Neeta Garg  8888   WESTBURY NY 11594 US 2222222222 [email protected]  UPS GRD 0.000 AXB479T;67.5900;2|842000YEL;4.2900;22|B956N;51.8900;1|XSPSPCL;67.0000;1890300;2999.9900;1|B956N;51.8900;1|XSPSPCL;210.0000;1|59047BKLG;9.9900;1A161BK;115.9900;1A161BK;115.9900;1A161BK;115.9900;1 AXB479T;|842000YEL;|B956N;Badge Custom Details : Style = B956, Dimensions = 2 9/16\" x 2 9/16\", Enamel Type = regular, Font = block-black, Panel 2 = , Panel 
+0

顺便问一下......我没有任何标识字段,或关键领域的限制。 – s15199d 2011-01-21 14:38:59

+0

我刚刚通过并删除了2列或3列的数据,并尝试导入。我这样做直到我排除了所有的列。我仍然不断收到“铸造规格无效字符值”错误。 – s15199d 2011-01-21 15:49:31

回答

12

我读到这里的这个链接http://luke.breuer.com/time/item/bcp_utility_gotchas/46.aspx

它说:

流延规范

无效字符值的值BCP试图上传到列是错误的数据类型。在最简单的情况下,这是因为将非整数值上传到整数列,错误的日期格式等。但是,如果{数据文件中的列数}!= {目标表中的列数/格式文件}。看到一个好方法,如果有一列#不匹配,如果错误文件吐出(?你没有使用-e error.txt,右)看起来是这样的:

 
#@ Row 1, Column 9: Invalid character value for cast specification @# 
2 0300 HC:36415 21 1 0  20070509 2 
3 0300 HC:36415 21 1 0  20070608 2 
#@ Row 2, Column 9: Invalid character value for cast specification @# 
4 0301 HC:80076 366 1 0  20070509 2 
5 0301 HC:80076 366 1 0  20070608 2 

注意什么BCP认为两行的数据构成一行上传到数据库。这个 是因为bcp知道列分隔符是{tab},除了最后一个是{newline} - 如果期望另一列,它会正确读取{新行}。

请检查日期格式是否正确写入。 http://support.microsoft.com/kb/883503

EDIT 2 - 1241PST

假设你的数据库是SQL Server,然后你想导入为datetime列数据类型,格式应该是这样的:

2011-01 -21 12:30:10.917

我想我就遇到了这个问题,一旦...

尝试打开你的单位文件(.txt与制表符分隔)到EXCEL,并从那里选择列并更改格式。您可以通过转到Excel中的DATA选项卡,选择列并点击“text to columns”,选择分隔符并完成。你所有的日期和时间应该出现。

然后,您必须再次选择列,单击右键,格式化单元格,然后选择类别列表中的DATE,然后将格式更改为SQL Server预期标准。如果这没有帮助,不知道还有其他什么,只要通过测试简单的小型测试用例来缩小问题的范围就可以了。