SQL Server - 批量插入列

时间:2012-06-14 00:22:04

标签: sql-server bulkinsert

我需要将csv文件插入sql server db。问题是我一直在

 Bulk load data conversion error (type mismatch or invalid character for
 the specified codepage)  error. this is repeated 10 times and 
 Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error.
The provider did not give any information about the error.
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".     

错误的特定列是bigint,主键,没有空字段。我确保所有5000条记录都有一个4位数字,并且没有空值。我厌倦了这个,只想在这个表中插入日期和数据值字段--CSResult。问题是sql server只是出错了,我认为它想要所有字段的值。 有没有办法将数据插入我想要的列? 任何想法。

     BULK INSERT [DB].[CsSchema].[CsResult] (
     FROM 'c:\june132012.csv'
     WITH
     (
     FIELDTERMINATOR = ',',
     ROWTERMINATOR = '\n'
     )

这是数据的样子:

    3857,2011-05-19 04:00:00.000,Y,,82,N,N,,4,1,1,10,,1,,535/31706815
    3858,2011-05-19 02:23:00.000,Y,,128,N,N,,4,1,1,10,,1,,535/31706815

这是DDL:

    ResultID bigint notnull 
    ResultDate datetime,notnull
    HasValue CHAR 1, notnull 
    Duration int, null 
    DataValue decimal 19,9, notnull 
    IsEdited CHAR 1, notnull 
    IsAnnotated CHAR 1, notnull 
    AddOnValue decimal 19,9, null 
    DataTypeID FK, int, notnull 
    ResultTypeID FK smallint, notnull 
    PatientID FK, int, notnull 
    DataSourceTypeID FK, smallint, notnull 
    MedicationID FK, int, null 
     DataDownloadID FK, int, null 
    SlotTypeID FK,smallint, null 
    DataSourceIdentity nvarchar 20, null

0 个答案:

没有答案