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

前端 未结 3 746
别跟我提以往
别跟我提以往 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:49

    Run SET DATEFORMAT ymd before the bulk insert statement

    Note that yyyy-mm-dd and yyyy-dd-mm are not safe in SQL Server generally: which causes this. Always use yyyymmdd. For more, see best way to convert and validate a date string (the comments especially highlight misunderstandings here)

提交回复
热议问题