批量插入类型不匹配或无效字符
问题描述:
我已经通过大量批量插入类型不匹配搜索问题进行了搜索,但尚未找到解决我确切问题的问题。我是批量插入CSV到本地SSMS datbase,但我不断收到错误:重复批量插入类型不匹配或无效字符
' (type mismatch or invalid character for the specified codepage) for row 2,
column 4 (DayNumber) '
这个错误直到SSMS到达错误的最大数量。之前我曾看到过这个错误,并一直能够解决这个问题。此外,我已经尝试了所有列在SO上的标准修复程序,但没有任何运气。三样东西贴出来给我介绍这个特别的错误,可能导致有人能够帮助我:
1) DayNumber is actually column 5 in the underlying CSV, not column 4
2) The DayNumber column simply has numeric values, I even with through row
by row to ensure there were no irregular characters contained in the
column
3) I have tried bulk inserting the CSV with this column set as a varchar,
int, numeric, and float - all of which produce the same error
任何帮助,在此将不胜感激,因为这是阻碍了整个项目。另外,我成功地将两个不同的CSV文件批量插入到相同的查询中。这些CSV文件与导致错误的文件存储在完全相同的文件夹中。
在此先感谢您的帮助!
样本数据下:
样品CSV数据:
Country Region Month Date DayNumber Location
USA California January 8/17/2016 48 USA
England London March 6/30/2017 91 England
USA Wyoming November 3/31/2017 90 USA
Canada Alberta January 12/31/2016 92 Canada
England Manchester February 9/30/2016 92 England
New Zealand Auckland July 6/30/2016 91 New Zealand
USA New York December 3/31/2016 91 USA
Canada Ontario April 12/31/2015 92 Canada
USA New York September 9/30/2015 92 USA
Australia Queensland January 6/30/2015 91 Australia
Australia Sydey March 3/31/2015 90 Australia
USA San Diego February 12/31/2014 92 USA
Canada Quebec October 9/30/2014 92 Canada
USA Florida August 6/30/2014 91 USA
样品BULK INSERT语句:
Create Table Table_A
(
[Country] varchar(max),
[Region] varchar(max),
[Month] varchar(max),
[Date] varchar(max),
[DayNumber] varchar(max),
[Location] varchar(max),
)
GO
BULK INSERT
Table_A
FROM 'C:\Path\CSV.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FIRSTROW = 2
);
你能提供您的CSV文件,我添加了样本数据和BULK INSERT语句原来的问题 – MBurnham
@MBurnham任何逗号作为字段终止符,它看起来像\ t和行终止符也可以是\ n \ r – ls101
@MBurnham感谢提供一吨的协助 – ls101