ADF 表达式函数“IF”带有超过2个条件

huangapple go评论66阅读模式
英文:

ADF Expression function "IF" with more than 2 conditions

问题

在SQL中,我们可以使用以下方式创建:

CASE WHEN 'A' THEN 1
     WHEN 'B' THEN 2
     WHEN 'C' THEN 3
ELSE 100

以下是对应的Azure Data Factory表达式:

@if(equals(variables('varInput'), 'a'), 'Ax', 
    if(equals(variables('varInput'), 'b'), 'Bx', 'C'))

要处理超过两个条件,可以使用嵌套的if语句。

然而,需要注意的是,Azure Data Factory表达式的if函数不支持超过两个参数。如果需要处理更多的条件,可以考虑使用嵌套的if语句或者其他逻辑来实现。

英文:

I Have question about Azure Data Factory Expression for function IF

in SQL we can create using

CASE WHEN 'A' Then 1
     when  'B' then 2
     when 'C' then 3
else 100

is this correct expression to IF?

@if(equals(variables('varInput'), 'a'), 'Ax', 
if(equals(variables('varInput'), 'b'), 'Bx', 'C'))

how to us "IF" function for more than 2 or we can use another Function like "Or"?

this is the expression that i built

@if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MMdd'),'0101'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(getPastTime(1,'Year'),'SE Asia Standard Time'),'yyyy'),'/','12'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')), if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'dd'),'01'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Month'),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')),concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')))

I want to create folder base on this case

  1. If today's date is 2023-01-01 then folder name path will be PRODUCT/2022/12/20221231
  2. if today's date is 2023-02-01 then folder name path will be PRODUCT/2023/01/20230131
  3. if todays date is 2023-03-02 then folder name path will be PRODUCT/2023/03/20230301

but expression IF doest support more than 2 arguments

答案1

得分: 1

不支持超过2个参数的IF函数。

为了提供多个条件,您可以使用嵌套的IF表达式,即在另一个IF内部的IF表达式。

我使用了与您尝试的相同表达式并出现了错误。

这个错误是因为在该表达式中,右括号)放错了位置。我在下面的图片中标出了这一点。

ADF 表达式函数“IF”带有超过2个条件

修正后的表达式

您可以使用以下表达式来满足您的需求。

英文:

>IF doesn't support more than 2 arguments.

In order to give multiple conditions, you can use the nested if expression i.e. if expression inside another if .

I used the same expression what you have tried and got error.

This error is because, closing paranthesis ) are misplaced in that expression. I have highlighted that in the below image.

ADF 表达式函数“IF”带有超过2个条件

Corrected expression :

You can use the below expression for your requirement.

@if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MMdd'),'0101'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(getPastTime(1,'Year'),'SE Asia Standard Time'),'yyyy'),'/','12','/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')), if(equals(formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'dd'),'01'), concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Month'),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd')),concat('PRODUCT/','daily/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'yyyy'),'/',formatDateTime(convertFromUtc(utcNow(),'SE Asia Standard Time'),'MM'),'/',formatDateTime(convertFromUtc(getPastTime(1,'Day'),'SE Asia Standard Time'),'yyyyMMdd'))))

答案2

得分: -2

检查case函数,这应该是你要找的,而不是if函数。

https://learn.microsoft.com/en-us/azure/data-factory/data-flow-expressions-usage#case

英文:

Check the case function as well, this should be the one you are looking for, not if function.

https://learn.microsoft.com/en-us/azure/data-factory/data-flow-expressions-usage#case

huangapple
  • 本文由 发表于 2023年3月1日 16:12:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601017.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定