如何轻松否定MS报告中的表达?

时间:2012-01-11 12:27:50

标签: c# vb.net visual-studio-2010 reporting-services crystal-reports

我正在将Crystal报告转换为MS报告。 我在Crystal报告中的表达是这样的:

=IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
0,
IIF(Fields!foo.Value Is Not Nothing and Fields!bar.Value Is Nothing,
Fields!foo.Value,
IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Not Nothing,
Fields!bar.Value * -1,
IIF(Fields!foo.Value Is Not Nothing and Fields!bar.Value Is Not Nothing,
Fields!foo.Value,
0
))))

Not在这里不起作用,即使文字是蓝色的。

我可以使用Not!之类的内容吗?或者我必须对IsNothing()

感到茫然

3 个答案:

答案 0 :(得分:2)

哦,我想通了,我只需要将Not移到表达式的开头。 这是我的VB.NET语法错误。来自C#,VB.NET和MS Reports对我来说都是新手,对不起。

=IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
0,
IIF(Not Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
Fields!foo.Value,
IIF(Fields!foo.Value Is Nothing and Not Fields!bar.Value Is Nothing,
Fields!bar.Value * -1,
IIF(Not Fields!foo.Value Is Nothing and Not Fields!bar.Value Is Nothing,
Fields!foo.Value,
0
))))

答案 1 :(得分:2)

您应该能够将表达简化为:

IIF(Not Fields!foo.Value Is Nothing, 
    Fields!foo.Value,
    IIF(Not Fields!bar.Value Is Nothing,
        Fields!bar.Value * -1,
        0))

编辑:要返回foo.Value - bar.Value,当两者都不为null时,请尝试:

= IIF(Not Fields!foo.Value Is Nothing, Fields!foo.Value, 0) -
  IIF(Not Fields!bar.Value Is Nothing, Fields!bar.Value, 0)

答案 2 :(得分:0)

试试这个:

=IIF((Fields!foo.Value.Equals(System.DBNull.Value)), "YES", "NO")
=IIF((Fields!foo.Value is System.DBNull.Value), "YES", "NO")
相关问题