如何编写SSIS switch/case 表达式?

发布于 2024-08-10 10:36:33 字数 262 浏览 2 评论 0原文

这是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遮云壑 2024-08-17 10:36:33

我使用了相当于 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)

一城柳絮吹成雪 2024-08-17 10:36:33

尽管从技术上讲,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!

屋顶上的小猫咪 2024-08-17 10:36:33

简单地将您的 ?: 语句构建为堆叠式

@[User::SomeVariable] == 2 ? "SomeVariable is 2"
:
@[User::SomeVariable] == 3 ? "SomeVariable is 3"
:
@[User::SomeVariable] == 4 ? "SomeVariable is 4" 
:
"SomeVariable is not 2,3,4 is actually" + @[User::SomeVariable] 

Simply structure your ?: statements as stacked

@[User::SomeVariable] == 2 ? "SomeVariable is 2"
:
@[User::SomeVariable] == 3 ? "SomeVariable is 3"
:
@[User::SomeVariable] == 4 ? "SomeVariable is 4" 
:
"SomeVariable is not 2,3,4 is actually" + @[User::SomeVariable] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文