简体   繁体   English

SSIS合并声明日期时间未更新

[英]SSIS Merge Statment Datetime not updated

I am using Merge Statement in my SSIS package. 我在SSIS包中使用合并语句。 The problem is that it doesn't update the datetime column when i run the package. 问题是,当我运行程序包时,它不会更新datetime列。 It inserts the datetime correctly but doesn't update them from NULL to some datetime if a new datetime is available in source database. 它可以正确插入日期时间,但是如果源数据库中有新的日期时间,则不会将其从NULL更新为某个日期时间。 Both source and destination has same column type (datetime(2),null). 源和目标具有相同的列类型(datetime(2),null)。 I am using the code below in SQL Task after truncating 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

You have a comma which shouldn't be there at the start of this line: 您应该在此行的开头添加一个逗号:

,targe.schedule_datetime=sourc.schedule_datetime

Also, you'll need to add this to take care of the NULLs: 另外,您需要添加它来处理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)

While ANSI_NULLS is set to ON, NULLs are basically unknowns, so they can't be evaluated to either 'equal to' or 'not equal to'. 虽然ANSI_NULLS设置为ON,但是NULL基本上是未知数,因此无法将它们评估为“等于”或“不等于”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM