英文:
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
- If today's date is 2023-01-01 then folder name path will be PRODUCT/2022/12/20221231
- if today's date is 2023-02-01 then folder name path will be PRODUCT/2023/01/20230131
- 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表达式。
我使用了与您尝试的相同表达式并出现了错误。
这个错误是因为在该表达式中,右括号)
放错了位置。我在下面的图片中标出了这一点。
修正后的表达式:
您可以使用以下表达式来满足您的需求。
英文:
>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.
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论