Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting services expression using Switch

I couldn't get this expression working with reporting services. I have to use IF and ELSE IF statement. Thank you for any suggestions.

= Switch( IsNothing(Fields!field_date.Value),"", Fields!set_flag.Value=1,"Declined", Fields!field_name.Value) 

Here is what I am trying to do.

If(IsNothing(Fields!field_date.Value)) Then "";

ElseIf Fields!set_flag.Value=1 Then "Declined";

Else Fields!field_name.Value
like image 785
nav100 Avatar asked Nov 03 '11 14:11

nav100


People also ask

How do you write a switch case in SSRS?

Using SWITCH Function in SSRSThe switch function allows multiple expressions as used in the 2nd line of the statement that contains "and". Similarly, or, orelse, and andalso could be used in this context. The 1=1 at the end is the "catch all" if none of the expression fit into the logical values.

How do you use expressions in SSRS report?

In Design view, click the text box on the design surface to which you want to add an expression. For a simple expression, type the display text for the expression in the text box. For example, for the dataset field Sales, type [Sales] . For a complex expression, right-click the text box, and select Expression.

What language does SSRS use for expressions?

Expressions are written in Microsoft Visual Basic, and can use built-in functions, custom code, report and group variables, and user-defined variables.


1 Answers

Doesn't SSRS use the VB Runtime Library? In which case, the switch statement is documented here and states that you must have an even number of elements passed in. If this is your issue, you're probably getting an ArgumentException thrown.

If you want to have a default return value, you'd have to add a dummy condition that always evaluates to true:

= Switch( IsNothing(Fields!field_date.Value),"", Fields!set_flag.Value=1,"Declined", True, Fields!field_name.Value) 
like image 97
Sir Crispalot Avatar answered Oct 01 '22 22:10

Sir Crispalot