SSIS Merge Statment 日期时间未更新

SSIS Merge Statment Datetime not updated

我在我的 SSIS 包中使用 Merge 语句。问题是当我 运行 包时它不会更新日期时间列。如果源数据库中有新的日期时间,它会正确插入日期时间但不会将它们从 NULL 更新为某个日期时间。 源和目标都具有相同的列类型 (datetime(2),null)。 我在 t运行cating staging table.

之后的 SQL 任务中使用下面的代码
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

此外,您需要添加此内容以处理 NULL:

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,但 NULL 基本上是未知数,因此无法将它们计算为 'equal to' 或 'not equal to'。