如何在SSRS报告中使用多个IIF条件?

时间:2016-02-09 08:45:27

标签: reporting-services ssrs-2008 multiple-columns nested-if

我想基于多个IFF条件在MS SSR中显示记录。任何的想法?请帮帮我!

我的桌子是"客户"和列是" 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;

我刚刚编写了C#语法来理解逻辑。我希望显示结果 例如:对于SSRS,我试过

=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"))," ")," ")

但不知道如何实施" cust2"," cust3"。有什么帮助吗?

2 个答案:

答案 0 :(得分:1)

这就是IIF表达式的工作原理。

  

IIF( CND DWT DWF

  • CND =检查的条件:
    在您的示例中:Len(First(Fields!cust1.value,"customername")) > 0(或IsNothing(First(Fields!cust1.value,"customername")),但您需要将其转过来)
  • DWT = true 时的操作/显示内容。所以当条件满足时。
    在您的示例中,您希望显示值。
  • DWF = false 时该怎么做/显示。熟悉"其他" if块的一部分。
    在您的示例中,您希望不显示任何内容或空字符串。

如果您确实想要嵌套多个IIF表达式,只需将 DWT DWF (或两者)替换为另一个IIF即可表达。这可以根据需要嵌套多次。这是一个简单的例子:

  

IIF( CND1 IIF( CND2 DWT2 DWF2 < strong>) IIF( CND3 DWT3 DWF3
   ------------------ | ________ DWT1 ________ | --- | ________ DWF1 ________ | ---

然而,当应用于你的例子时,我不相信有必要筑巢。以下表达式应该为您提供所需的结果:

=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"), "")

答案 1 :(得分:0)

作为您的关注

IIF( CND1 , IIF( CND2 , DWT2 , DWF2 ) , IIF( CND3 , DWT3 , DWF3 ) )

我对我的表情做了一些改动,比如

=First(Fields!cust1.value,"customername")&
IIF(First(Fields!Cust2.value,"customername")+" ">" ",

IIF(First(Fields!cust3.value,"customername")+" ">" ",

", "+First(Fields!Cust3.Value,"customername")+
", "+First(Fields!Cust2.Value,"customername")," "),

IIF(First(Fields!cust4.value,"customername")+" ">" ",
", "+First(Fields!Cust4.Value,"customername")+
", "+First(Fields!Cust3.Value,"customername")+
", "+First(Fields!Cust2.Value,"customername")," "),

IIF(First(Fields!cust5.value,"customername")+" ">" ",

", "+First(Fields!Cust5.Value,"customername")+
", "+First(Fields!Cust4.Value,"customername")+
", "+First(Fields!Cust3.Value,"customername")+
", "+First(Fields!Cust2.Value,"customername"), 
" and"+First(Fields!cust2.Value,"customername")),


" ")

但是我的错误仍会在表达式上出现错误吗?