问题
I want to display records in MS SSRs based on multiple IFFs Condition. Any idea? Please help me!
My table is "customers" and columns are "cust1", "cust2", "cust3", "cust4"
if(cust1.value!=null)
{
display cust1;
if(cust2.value!=null)
{
display cust1+","+cust2;
}
if(cust3.value!=null)
{
diplay cust1+","+cust2+"and+"+cust3
}
if(cust4.value!=null)
{
diplay cust1+","+cust2+","+cust3+"and"+cust4;
}
}else
diplay cust1;
I just wrote C# syntax for understand logic. I want to display like result Ex: for SSRS I tried
=First(Fields!cust1.value,"customername")&
IIF(First(Fields!Cust2.value,"customername")+" ">" ",
IIF(First(Fields!Cust3.value,"customername")+" ">" ",
IIF(First(Fields!cust4.value,"customername")+" ">" ",
", "+First(Fields!Cust4.Value,"customername")+
", "+First(Fields!Cust3.Value,"customername")+
", "+First(Fields!Cust2.Value,"customername"),
" and"+First(Fields!cust1.Value,"customername"))," ")," ")
but no idea how to implement "cust2", "cust3". Any help?
回答1:
This is how the IIF expression works.
IIF( CND , DWT , DWF )
- CND = The condition that is checked:
In your example:Len(First(Fields!cust1.value,"customername")) > 0
(orIsNothing(First(Fields!cust1.value,"customername"))
but then you need to turn it around) - DWT = What to do/display when true. So when the condition is met.
In your example you wish to display the value. - DWF = What to do/display when false. Familiar to the "else" part of an if-block.
In your example you wish to display nothing or an empty string.
If you actually want to nest multiple IIF expressions it is possible by just replacing a DWT or DWF (or both) with another IIF expression. This can be nested as many times as you desire. Here is a simple example:
IIF( CND1 , IIF( CND2 , DWT2 , DWF2 ) , IIF( CND3 , DWT3 , DWF3 ) )
------------------|________DWT1________|---|________DWF1________|---
However, when applied on your example I don't believe it is necessary to nest. The following expression should give you the desired result:
=IIF(Len(First(Fields!cust1.value,"customername")) > 0, First(Fields!cust1.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust2.value,"customername")) > 0, First(Fields!cust2.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust3.value,"customername")) > 0, First(Fields!cust3.value,"customername") + " ", "") +
IIF(Len(First(Fields!cust4.value,"customername")) > 0, First(Fields!cust4.value,"customername"), "")
来源:https://stackoverflow.com/questions/35287434/how-to-use-multiple-iifs-condition-in-expression-in-ssrs-reports