bulk insert a date in YYYYMM format to date field in MS SQL table

前端 未结 3 748
别跟我提以往
别跟我提以往 2020-12-22 03:08

I have a large text file (more than 300 million records). There is a field containing date in YYYYMM format. Target field is of date type and I\'m using MS SQL 2008 R2 serve

3条回答
  •  北海茫月
    2020-12-22 03:25

    You may not care about the day but SQL does.
    YYYYMM is not a valid SQL date.
    A date must have day component.
    In your example it parsed it down as YYMMDD.
    You could insert into a VarChar as Jaimal proposed then append a 01 and convert.

    I would read in the data in .NET add the 01 and use DateTime.ParseExact and insert row by row asynch. You can catch any parse that is not successful.

    Or you might be able to do a global replace in the csv "," to "01,". It is worth a try.

提交回复
热议问题