BCP file format for SQL bulk insert of CSV file

梦想与她 提交于 2020-01-05 08:12:29

问题


I'm trying a bulk insert of a csv file into a SQL table using BCP but can't fix this error: "The column is too long in the data file for row 1, column 2. Verify that the field terminator and row terminator are specified correctly." - Can anyone help please?

Here's my SQL code:

BULK INSERT UKPostCodeStaging
FROM 'C:\Users\user\Desktop\Data\TestFileOf2Records.csv'
WITH (
DATAFILETYPE='char',
FIRSTROW = 1,
FORMATFILE = 'C:\Users\User\UKPostCodeStaging.fmt');

Here's my test data contained in TestFileOf2Records.csv:

"HS1 2AA",10,14,93,"S923","","S814","","S1213","S132605"
"HS1 2AD",10,14,93,"S923","","S814","","S1213","S132605"

And here's my BCP file that I have attempted to edit appropriately:

10.0
11
1   SQLCHAR  0  0  "\""      0  FIRST_QUOTE                 SQL_Latin1_General_CP1_CI_AS
2   SQLCHAR  8  0  "\","     1  PostCode                    SQL_Latin1_General_CP1_CI_AS
3   SQLINT   1  0  ","       2  PositionalQualityIndicator  ""
4   SQLINT   1  0  ","       3  MetresEastOfOrigin          ""
5   SQLINT   1  0  ",\""     4  MetresNorthOfOrigin         ""
6   SQLCHAR  8  0  "\",\""   5  CountryCode                 SQL_Latin1_General_CP1_CI_AS
7   SQLCHAR  8  0  "\",\""   6  NHSRegionalHACode           SQL_Latin1_General_CP1_CI_AS
8   SQLCHAR  8  0  "\",\""   7  NHSHACode                   SQL_Latin1_General_CP1_CI_AS
9   SQLCHAR  8  0  "\",\""   8  AdminCountyCode             SQL_Latin1_General_CP1_CI_AS
10  SQLCHAR  8  0  "\",\""   9  AdminDistrictCode           SQL_Latin1_General_CP1_CI_AS
11  SQLCHAR  8  0  "\"\r\n"  10 AdminWardCode               SQL_Latin1_General_CP1_CI_AS

Any ideas where I am going wrong? thanks

来源:https://stackoverflow.com/questions/12200174/bcp-file-format-for-sql-bulk-insert-of-csv-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!