[英]SSIS Derived Column Expression for CASE.. WHEN
I have the following SQL code that I am trying to convert inao a SSIS 2012 Derived Column Expression: 我有以下SQL代码,我正在尝试将其转换为SSIS 2012派生列表达式:
QUATER=
CASE
WHEN DATEPART(M, @BD) BETWEEN 1 AND 3 THEN 'Q1'
WHEN DATEPART(M, @BD) BETWEEN 4 AND 6 THEN 'Q2'
ELSE 'OTHER'
END
My Expression looks like this, and it works: 我的表情看起来像这样,并且有效:
DATEPART("M", @[User::BD]) == 1 ? "Q1":
(DATEPART("M", @[User::BD]) == 2 ? "Q1":
(DATEPART("M", @[User::BD]) == 3 ? "Q1":
(DATEPART("M", @[User::BD]) == 4 ? "Q2":
(DATEPART("M", @[User::BD]) == 5 ? "Q2":
(DATEPART("M", @[User::BD]) == 6 ? "Q2" : "OTHER"
)))))
Is there a more elegant way to do this? 有没有更优雅的方法可以做到这一点?
Not much more exciting, but this should be equivalent: 没有什么更令人兴奋的了,但这应该是等效的:
DATEPART("M", @[User::BD]) <= 3 ? "Q1":
(DATEPART("M", @[User::BD]) <= 6 ? "Q2" : "OTHER"
)
Likewise You could use quarter instead of month: 同样,您可以使用季度而不是月份:
DATEPART("q", @[User::BD]) <= 2 ? "Q"+DATEPART("q", @[User::BD]) : "OTHER"
Can't test that string concatenation, you may need to convert the DATEPART()
output to text. 无法测试该字符串的串联,您可能需要将
DATEPART()
输出转换为文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.