Reputation: 195
I was doing reporting on SSRS reports. I need to write an expression for the Textbox to show different input parameters if provided. I have tried writting the expression. But couldn't make it perfect. Here I provided sample code in which i need to have a SSRS expression. Anyone help me provide the same expression in SSRS format.
Code
If(Parameters!FromCreationdate.Value !=null && Parameters!ToCreationdate.Value !=null)
{
"Created Date:"+ Parameters!FromCreationdate.Value + "To Created Date:"+Parameters!ToCreationdate.Value;
}
else if(Parameters!FromCreationdate.Value !=null)
{
"Created Date:"+ Parameters!FromCreationdate.Value;
}
else if(Parameters!ToCreationdate.Value !=null)
{
"To Created Date:"+ Parameters!ToCreationdate.Value;
}
Expression
=IIf(isnothing(Parameters!FromCreationdate.Value),"", "From Creation Date:"+Parameters!FromCreationdate.Value, iif(isnothing(Parameters!FromCreationdate.Value)),"", "To Creation Date:"+Parameters!FromCreationdate.Value)
Thanks
Upvotes: 3
Views: 23811
Reputation: 474
Using SWITCH is a better method, but if you still need/want to nest your IIF statements for some reason, it would be like this instead:
=IIF(Not IsNothing(Parameters!FromCreationdate.Value) And Not IsNothing(Parameters! ToCreationdate.Value),
"Created Date: " + Parameters!FromCreationdate.Value +
" To Created Date: " + Parameters!ToCreationdate.Value,
IIF( Not IsNothing(Parameters!FromCreationdate.Value),
"Created Date: " + Parameters!FromCreationdate.Value,
IIF( Not IsNothing(Parameters!ToCreationdate.Value),
"To Created Date: " + Parameters!ToCreationdate.Value,
""
)
)
)
Alternatively, you could also do this:
=IIF( Not IsNothing( Parameters!FromCreationdate.Value ),
"Created Date: " + Parameters!FromCreationdate.Value,
"" ) +
IIF( Not IsNothing( Parameters!FromCreationdate.Value ) AND
Not IsNothing ( Parameters!ToCreationdate.Value ),
" ", "" ) +
IIF( Not IsNothing( Parameters!ToCreationdate.Value ),
"To Created Date: " + Parameters!ToCreationdate.Value,
"" )
You may need to change the empty string ("") to Nothing if you are creating reports in SSRS 2005 and deploying to 2008. Doing this either with certain export formats (or possibly it was certain browsers) has caused the empty string to look like a dash when we had Bold set on the text field.
Upvotes: 2
Reputation: 166336
Have a look at Expression Examples (Report Builder and SSRS) and more specifically at SWITCH
The Switch function is useful when you have three or more conditions to test. The Switch function returns the value associated with the first expression in a series that evaluates to true
So you would use it something like
=SWITCH(
TEST_CONDITION_1,VALUE_1,
TEST_CONDITION_2,VALUE_2,
TEST_CONDITION_3,VALUE_3,
....
TEST_CONDITION_N,VALUE_N
)
Upvotes: 4