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 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01