批量插入不接受小数点

时间:2019-03-13 17:40:38

标签: sql-server bulkinsert

我正在使用批量插入功能将多个CSV文件从一个文件夹导入到我的表格中。

使用的sql im是。

set @sql = 'BULK INSERT RawActivity FROM ''' + @path + @filename + ''' '
           + '     WITH ( 
                   FIELDTERMINATOR = '','', 
                   FORMATFILE = ''C:\\Users\\pllaguno\\Desktop\\Febrero\\format.fmt'',
                   ROWTERMINATOR = ''\n'', 
                   FIRSTROW = 2 
                ) '

我的CSV文件如下,我将在sql向我发送错误的行中添加一些行,而不是(行号在前)行。

2 Unknown Driver,2/1/2019,4651,Seat Belt Alert Start,12:00:06 AM,46,km/h,0.4,km,,,,,"3 Sur 256, Sevilla, 15840 Ciudad de México, CDMX, Mexico",19.40908,-99.12303
146 Unknown Driver,2/1/2019,9804,Seat Belt Alert End,12:12:36 AM,,-,,-,,,,,"[Cedis Saltillo], Perif. Luis Echeverría 3951, Centenario, 25050 Saltillo, Coah., Mexico",25.40517,-100.98308
152 Unknown Driver,2/1/2019,10319,Seat Belt Alert End,12:12:58 AM,,-,,-,,,,,"[Cedis Monterrey Centro], Calle Pedro María Anaya 1210, Industrial, 64440 Monterrey, N.L., Mexico",25.69608,-100.32383
153 Unknown Driver,2/1/2019,13042,Seat Belt Alert End,12:12:59 AM,,-,25.0,km,,,,,"Av. Eugenio Garza Sada Sur SN-S""OXXOEXPRES"", Roma, 64700 Monterrey, N.L., Mexico",25.65527,-100.29421

给出的错误是(编辑:该行应为153,问题是某些行内包含更多引号)

Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 152, column 15 (Latitude).

我的.fmt文件是这样的:

11.0
16
1   SQLCHAR   0  8000   ","      1     Driver         SQL_Latin1_General_CP1_CI_AS
2   SQLCHAR   0  40   ","      2     ActivityDate         SQL_Latin1_General_CP1_CI_AS
3   SQLCHAR   0  8000   ","      3     Vehicle         SQL_Latin1_General_CP1_CI_AS
4   SQLCHAR   0  40   ","      4     Event         SQL_Latin1_General_CP1_CI_AS
5   SQLCHAR   0  8000   ","      5     EventTime         SQL_Latin1_General_CP1_CI_AS
6   SQLCHAR   0  40   ","      6     Speed         SQL_Latin1_General_CP1_CI_AS
7   SQLCHAR   0  8000   ","      7     SpeedUnit         SQL_Latin1_General_CP1_CI_AS
8   SQLCHAR   0  40   ","      8     TripDistance         SQL_Latin1_General_CP1_CI_AS
9   SQLCHAR   0  8000   ","      9     TripUnit         SQL_Latin1_General_CP1_CI_AS
10   SQLCHAR   0  40   ","      10     OnSiteTime         SQL_Latin1_General_CP1_CI_AS
11   SQLCHAR   0  8000   ","      11     HDOP         SQL_Latin1_General_CP1_CI_AS
12   SQLCHAR   0  40   ","      12     NumSatellites         SQL_Latin1_General_CP1_CI_AS
13   SQLCHAR   0  8000   ",\""      13     Channel         SQL_Latin1_General_CP1_CI_AS
14   SQLCHAR   0  40   "\","     14     Location         SQL_Latin1_General_CP1_CI_AS
15   SQLCHAR   0  8000   ","      15     Lattitude         SQL_Latin1_General_CP1_CI_AS
16   SQLCHAR   0  40   "\r\n"      16     Longitude         SQL_Latin1_General_CP1_CI_AS

“纬度”列为小数(9,6)

1 个答案:

答案 0 :(得分:-1)

我可以看到与记录格式有两个区别。

1)主机文件的数据长度(以字节为单位)可以为0,因为您正在处理带分隔符的文件。

2)非文本列不需要与它们关联的排序规则。因此,将纬度和经度排序规则设置为“”。

最后,“纬度”是错字吗?

这是fmt文件格式的MS doc页面。 https://docs.microsoft.com/en-us/sql/relational-databases/import-export/non-xml-format-files-sql-server?view=sql-server-2017