派生列中的嵌套IF ELSE

问题描述 投票:1回答:1

我有以下逻辑将日期存储在BI_StartDate中,如下所示:

  • 如果UpdatedDate不为空,则BI_StartDate = UpddatedDate
  • ELSE BI_StartDate采用EntryDate值,如果EntryDate为null然后BI_StartDate = CreatedDate
  • 如果CreatedDate为NULL,则BI_StartDate = GetDATE()

我正在使用派生列,如下所示:

ISNULL(UpdatedDateODS)  ? EntryDateODS : (ISNULL(EntryDateODS) ? CreatedDateODS :
(ISNULL(CreatedDateODS) ? GETDATE()  ))

我收到此错误:

表达式“ ISNULL(UpdatedDateODS)?EntryDateODS:(ISNULL(EntryDateODS)?CreatedDateODS:(ISNULL(CreatedDateODS)?GETDATE()))”上的“派生列.Outputs [派生列输出] .Columns [派生列1]“无效。

sql sql-server ssis
1个回答
0
投票

您正在寻找第一个非null,它是SSIS数据流(派生列)中不存在的合并。

我建议一个非常简单的脚本组件:

Row.BIStartDate = Row.UpdateDate ?? Row.EntryDate ?? Row.CreatedDate ?? DateTime.Now;

这是输入列屏幕:

enter image description here

这是输入和输出:

enter image description here

然后将上面的代码添加到行处理部分:

public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        /*
         * Add your code here
         */

        Row.BIStartDate = Row.UpdateDate ?? Row.EntryDate ?? Row.CreatedDate ?? DateTime.Now;
}
© www.soinside.com 2019 - 2024. All rights reserved.