如何编写SSIS switch/case 表达式?
这是一个 SQL Server Integration Services (SSIS) 表达式问题(我对此还很陌生)。
我想在派生列转换中编写一个 switch/case 表达式 - 基本上,新列可以根据输入列的值有 5 个不同的可能值。我从谷歌得到的只是(条件)? (真值):(假值)技术,但这仅提供了两个可能的值。 SSIS 表达式是否有 switch/case 类型表达式?
我想过使用顺序派生列转换,或创建临时查找表,但这似乎比实际应该的更复杂。
谢谢。
This is a SQL Server Integration Services (SSIS) expressions question (I'm pretty new to it).
I would like to write a switch/case expression in a Derived Column transform - basically the new column can have 5 different possible values, based on the value of an input column. All I got from Google is the (condition) ? (true value) : (false value) technique, but this only provides for two possible values. Does SSIS expressions have a switch/case type expression?
I thought of using sequential Derived Column transforms, or creating a temporary lookup table, but that just seems more complicated that it really should be.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用了相当于 if-elseif-else 语句来解决问题,如下所示:
(condition1) ? (真值1):(条件2)? (真值2) : (假值)
I have used the equivalent of a if-elseif-else statement to solve the problem, like this:
(condition1) ? (true value1) : (condition2) ? (true value2) : (false value)
尽管从技术上讲,avesse 的答案是可行的,但编写/维护表达式并不是最有趣的任务。
为了避免在派生列转换中编写复杂的表达式,我建议使用脚本转换。这样做允许您使用 .NET 代码编写 switch 语句,更易于编写和维护。您的同事会很感激的!
Even though, technically, the answer by avesse will work, writing/maintaining the expression is not the most interesting task.
To avoid writing complex expressions in the Derived Column transformation, I'd recommend to use a Script transformation. Doing that allows you to use .NET code to write a switch statement, much nicer to write and maintain. Your colleagues will appreciate it!
简单地将您的 ?: 语句构建为堆叠式
Simply structure your ?: statements as stacked