SQL Server批量插入空值到时间列

编程入门 行业动态 更新时间:2024-10-11 21:22:13
本文介绍了SQL Server批量插入空值到时间列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在从大容量插入语句中插入空值时遇到麻烦。

I'm having trouble inserting null value from a bulk insert statement.

两列可以为空,且ID为标识。

Two columns are nullable and the Id is identity.

int 可为null的值可以很好地工作,但 time 不能。

The int nullable workd out fine, but the time doesn't.

  • 以下是批量声明:

  • Here the bulk statement:

BULK INSERT Circulation FROM '.....file.cs' WITH ( FIRSTROW = 2, MAXERRORS = 0, FIELDTERMINATOR = ',', ROWTERMINATOR = '', KEEPNULLS)

  • 以下是csv的摘录:

  • Here is an extract of the csv:

    ID, IDStopLine, IDException, Hour, PositionHour, Day ,28, 8, 12:20, 52, 0 ,29, 163, , 1,

  • 表示我试图在这两个列中插入空值。结果是int列为NULL和time列为00:00:00

    Meaning that I'm trying to insert nulls in those both columns. The result is ithe int column with NULL and the time column with 00:00:00

    推荐答案

    我不知道为什么在时间列中插入00: 00:00,但如果需要NULL,则可以尝试创建触发器并使用FIRE_TRIGGER参数运行BULK INSERT

    I don't know why time column insert with 00:00:00, but if you need NULL then it is possible to try create trigger and run BULK INSERT with FIRE_TRIGGER argument

    CREATE TRIGGER dateNull ON dbo.Circulation INSTEAD OF INSERT AS BEGIN INSERT dbo.Circulation(IdStopline, IdException, Hour, PositionHour, Day) SELECT IdStopline, IdException, NULLIF(Hour, '00:00:00.0000000'), PositionHour, Day FROM inserted END BULK INSERT dbo.Circulation FROM 'you_file.csv' WITH (FIRSTROW = 2, MAXERRORS = 0, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', KEEPNULLS, FIRE_TRIGGERS)

    更多推荐

    SQL Server批量插入空值到时间列

    本文发布于:2023-10-26 17:49:12,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1530892.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:批量   时间   SQL   Server   空值到

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!