bulk insert a date in YYYYMM format to date field in MS SQL table(将 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.
- 将日期作为 varchar 字段插入,然后运行查询以转换将日期写入 DateTime 字段
- 使用 SSIS
这篇关于将 YYYYMM 格式的日期批量插入 MS SQL 表中的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 YYYYMM 格式的日期批量插入 MS SQL 表中的日期字段


基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01