这是RS表达标准还是黑客攻击

时间:2012-10-15 15:40:17

标签: sql-server reporting-services ssrs-2008

我正在使用Switch并且表达式似乎没有明显的ELSE部分所以我最终得到了以下内容但感觉有点像黑客 - 是它?

它有效 - 因为它修改了字符串,如果它是foobar,但任何其他产品字符串都是单独的:

=Switch(Fields!Product.Value = "foo" , "foo (incl sad)", 
       Fields!Product.Value = "bar", "bar (incl sick)",
       Cdbl(1)=Cdbl(1), Fields!Product.Value)

3 个答案:

答案 0 :(得分:2)

如果有效,它就有效。你也可以使用IIF(Fields!Product.Value =“foo”,“foo2”,IIF(Fields!Product.Value =“bar”,“bar2”,Fields!Product.Value)

答案 1 :(得分:0)

您可以使用该开关,您可以做的另一件事是使用MSDN中的=IIF(...)

  

Iif函数根据是否返回两个值中的一个   表达式是否真实。以下表达式使用Iif   函数返回布尔值True,如果LineTotal的值   超过100.否则返回False:

另一个表达式可以包含另一个IIF,因此您不仅限于一个IIF。 所有RS表达式都可以在这里找到:

http://msdn.microsoft.com/en-us/library/ms157328.aspx

答案 2 :(得分:0)

因为有人提出要求:

=Switch(Fields!Product.Value = "foo" , "foo (incl sad)",  
        Fields!Product.Value = "bar", "bar (incl sick)", 
        Cdbl(1)=Cdbl(1), Fields!Product.Value) 

会变成

=Switch(Fields!Product.Value = "foo" , "foo (incl sad)",  
        Fields!Product.Value = "bar", "bar (incl sick)", 
        true, Fields!Product.Value) 

我认为哪个更具可读性 - 我可以理解1 = 1但是,任何人都可以告诉我原始代码中双精度的转换是什么?

据我所知,这是从switch语句返回'else'的唯一方法。否则返回null / Nothing(分别对于c#/ VB大师)。