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 表中的日期字段


基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01