In an rdlc report I want to compare integers like
if(expression)
{
// do something
}
else if(expression)
{
// do something else
}
What is the syntax for this?
Rather than using nested IIF statements I prefer the Switch statement.
From the MSDN...
=Switch(
Fields!PctComplete.Value >= 10, "Green",
Fields!PctComplete.Value >= 1, "Blue",
Fields!PctComplete.Value = 1, "Yellow",
Fields!PctComplete.Value <= 0, "Red"
)
Hope it helps :)
You will have to nest IIF statements like this:
= IIF (expression = 1, "Is 1", IIF (expression = 2, "Is 2"))
Use switch instead. I know I reached late here,but hope that it may help someone.
=Switch(Fields!Parameter.value = 2,"somethingnew", 1=1 ,"somethingelse")
1=1 refers to default in switch case.
It is similar like
if(Parameter.Value == 2)
{
somethingnew
}
else
{
somethingelse
}
This is the Syntax for your requirement:
=IIf(CInt(Fields!expression1.value)==1,true,IIf(Cint(Fields!expression2.value)==2,true,nothing))
In true part you can specify the statement to be executed.
In addition to what has been said, the If(condition, true_part, false_part) ternary operator should (with one I) be preferred over the IIf(condition, true_part, false_part) function (with two I's) in most cases.
The If() ternary operator will short-circuit evaluate only the part that corresponds to condition outcome (e.g. a condition that is True will only evaluate the true_part).
The IIf() function will always evaluate the condition and both parts, because it is just a function call and all parameters of the function will be evaluated before the call.
Since developers usually expect short-circuit evaluation in IF statements, the usage of the If() ternary operator should be the default choice.
It allows you to run expressions that check for Nothing, like the following, which would not work without lazy evaluation:
=If(Fields!Blog.Value IsNot Nothing, Fields!Blog.Value.Name, "Blog is missing")
You could also try this example
= IIF(Parameters!expression.Value = True, 'somethingnew', 'somethingelse')