2011-01-21 89 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預期標準。如果這沒有幫助,不知道還有其他什麼,只要通過測試簡單的小型測試用例來縮小問題的範圍就可以了。