Datetime SSIS合并状态日期时间未更新
我正在SSIS包中使用Merge语句。问题是当我运行包时,它不会更新datetime列。它正确插入日期时间,但如果源数据库中有新的日期时间可用,则不会将其从NULL更新为某个日期时间。 源和目标都具有相同的列类型datetime2,null。 截断临时表后,我将在SQL任务中使用下面的代码Datetime SSIS合并状态日期时间未更新,datetime,ssis,merge-statement,Datetime,Ssis,Merge Statement,我正在SSIS包中使用Merge语句。问题是当我运行包时,它不会更新datetime列。它正确插入日期时间,但如果源数据库中有新的日期时间可用,则不会将其从NULL更新为某个日期时间。 源和目标都具有相同的列类型datetime2,null。 截断临时表后,我将在SQL任务中使用下面的代码 MERGE abc.dbo.invoices AS targe USING (SELECT ID ,cash_received_date ,schedule_datetime
MERGE abc.dbo.invoices AS targe
USING (SELECT
ID
,cash_received_date
,schedule_datetime
,delivery_date
FROM Staging.dbo.tmpabcinvoices) AS sourc
ON targe.id = sourc.id
WHEN MATCHED and
targe.schedule_datetime <> sourc.schedule_datetime
or
targe.delivery_date <> sourc.delivery_date
or
targe.cash_received_date <> sourc.cash_received_date
THEN UPDATE SET
,targe.schedule_datetime=sourc.schedule_datetime
,targe.delivery_date=sourc.delivery_date
,targe.cash_received_date=sourc.cash_received_date
WHEN NOT MATCHED THEN
INSERT(
old_invoiceid
,cash_received_date
,schedule_datetime
,delivery_date
)
VALUES
(
sourc.old_invoiceid
,sourc.cash_received_date
,sourc.schedule_datetime
,sourc.delivery_date
);
GO
您有一个逗号,它不应该出现在此行的开头:
,targe.schedule_datetime=sourc.schedule_datetime
此外,您还需要添加以下内容来处理空值:
targe.schedule_datetime <> sourc.schedule_datetime
or (targe.schedule_datetime IS NULL AND sourc.schedule_datetime IS NOT NULL)
or targe.delivery_date <> sourc.delivery_date
or (targe.delivery_date IS NULL AND sourc.delivery_date IS NOT NULL)
or targe.cash_received_date <> sourc.cash_received_date
or (targe.cash_received_date IS NULL AND sourc.cash_received_date IS NOT NULL)
虽然ANSI_NULLS设置为ON,但NULLS基本上是未知的,因此它们不能计算为“等于”或“不等于”。谢谢,这很有帮助。