将 YYYYMM 格式的日期批量插入 MS SQL 表中的日期字段

我有一个大文本文件(超过 3 亿条记录).有一个字段包含 YYYYMM 格式的日期.目标字段是日期类型,我使用的是 MS SQL 2008 R2 服务器.由于数据量巨大,我更喜欢使用批量插入.这是我已经完成的:

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 server. Due to huge amount of data I'd prefer to use bulk insert. Here's what I've already done:

bulk insert Tabela_5
from 'c:users...	able5.csv'
with
(
    rowterminator = '
',
    fieldterminator = ',',
    tablock
)
select * from Tabela_5

201206 在服务器上原来是 2020-12-06 ,而我希望它是 2012-06-01(我不在乎这一天).有没有办法将这种格式的日期批量插入到日期类型的字段中?

201206 in file turns out to be 2020-12-06 on server, whereas I'd like it to be 2012-06-01 (I don't care about the day). Is there a way to bulk insert date in such format to a field of date type?

亲切的问候马切伊皮图查

kind regards maciej pitucha

推荐答案

没有办法在批量插入上执行此操作.您有 2 个选项.

There isn't a way to do this on Bulk Insert. You have 2 options.

  1. 将日期作为 varchar 字段插入,然后运行查询以转换将日期写入 DateTime 字段
  2. 使用 SSIS

相关文章