我无法使用BCP将制表符分隔的* .txt文件中的数据导入到我的SQL表中。
我不断收到两个“强制转换规范的无效字符值”错误。
作为测试,我手动插入了几行。然后我BCP将这些行查询到* .txt文件。然后我尝试用BCP导入相同的数据。
通过该测试,我得到了“转换规范的无效字符值”错误和“BCP数据文件中遇到的意外EOF”
有没有办法告诉哪些行/列会触发错误?
有关调试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 neeta@orderdynamics.com <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 neeta@orderdynamics.com 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 neeta@orderdynamics.com <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 neeta@orderdynamics.com 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 neeta@orderdynamics.com <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 neeta@orderdynamics.com 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 neeta@orderdynamics.com <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 neeta@orderdynamics.com 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 :(得分:12)
我在这里阅读了这个链接http://luke.breuer.com/time/item/bcp_utility_gotchas/46.aspx
它说:
强制转换规范的字符值无效 尝试上传到列的bcp值是错误的数据类型。在最简单的情况下,这是由于将非整数值上传到整数列,错误的日期格式等。但是,如果{数据文件中的列数}!= {目标表中的列数,也会发生这种情况/格式文件}。查看是否存在#mismatch列的好方法是错误文件是否吐出(你确实使用了-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} - 如果它期待另一个列,它会在{newline}之前读到。
请检查日期格式是否写得正确。 http://support.microsoft.com/kb/883503
编辑2 - 1241PST
假设您的数据库是SQL Server,并且您尝试导入的列数据类型是datetime,则格式应如下所示:
2011-01-21 12:30:10.917
我想我曾遇到过这个问题......
尝试打开您的平面文件(带制表符分隔的.txt)到EXCEL,然后从那里选择列并更改格式。您可以通过转到Excel中的DATA选项卡,选择列,然后单击“text to columns”,选择分隔,然后完成。您的所有日期和时间都应该出现。
然后,您必须再次选择该列,右键单击,格式化单元格,并在类别列表中选择DATE,并将格式更改为SQL Server预期标准。如果这没有帮助,除了通过使用表/数据库测试简单的小测试用例来尝试缩小问题之外还不知道还有什么。