Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server ms SSRS 2008 R2:显示计算值#错误_Sql Server_Reporting Services_Ssrs 2008 - Fatal编程技术网

Sql server ms SSRS 2008 R2:显示计算值#错误

Sql server ms SSRS 2008 R2:显示计算值#错误,sql-server,reporting-services,ssrs-2008,Sql Server,Reporting Services,Ssrs 2008,报告将显示两列Foo和Bar Foo的某些行为空,某些行具有数值: Foo: +----+ | | +----+ |10.0| +----+ 然后是Bar列,该列将从Foo中获取值并向其中添加10,报告应生成如下结果: Foo: Bar: +----+----+ | | | +----+----+ |10.0|20.0| +----+----+ Public Function MyAdd(val As Object) As Nullable(Of Integer)

报告将显示两列Foo和Bar

Foo的某些行为空,某些行具有数值:

 Foo:
+----+
|    |
+----+
|10.0|
+----+
然后是Bar列,该列将从Foo中获取值并向其中添加10,报告应生成如下结果:

 Foo: Bar:
+----+----+
|    |    |
+----+----+
|10.0|20.0|
+----+----+
Public Function MyAdd(val As Object) As Nullable(Of Integer)
        If TypeOf(val) Is Integer Then
             Return val + 10
        Else
             Return Nothing
        End If
End Function
这是我用来确定Foo是否为条内数字的表达式:

=IsNumeric(ReportItems!FooBox.Value)
这就是表达式将产生的结果:

 Foo: Bar:
+----+-----+
|    |False|
+----+-----+
|10.0|True |
+----+-----+
好的,到目前为止,这正是我想要的方式,因此我这样写我的表达式:

=IIf(IsNumeric(ReportItems!FooBox.Value),
            ReportItems!FooBox.Value +10,
            "")
这将产生以下结果:

Foo: Bar:
+----+------+
|    |#Error|
+----+------+
|10.0|20.0  |
+----+------+
大多数Bizare,当我删除IIf的Truepart中的小加法时,它将执行:

=IIf(IsNumeric(ReportItems!FooBox.Value),
                ReportItems!FooBox.Value,
                "")

Foo:   Bar:
+----+------+
|    |      |
+----+------+
|10.0|10.0  |
+----+------+
这几乎就好像三元运算符的“错误”部分无论如何都会被执行,从而生成这个castError或其他任何东西


如何正确转换值以显示前面解释的结果?

确实-使用IIf将导致两个语句(真和假)都被求值,从而导致出现错误

在您的情况下,我将创建自己的函数来处理此问题-您可以将其放置在报表的“代码”字段中(单击页面区域外部以访问报表对象)

您的函数可能如下所示:

 Foo: Bar:
+----+----+
|    |    |
+----+----+
|10.0|20.0|
+----+----+
Public Function MyAdd(val As Object) As Nullable(Of Integer)
        If TypeOf(val) Is Integer Then
             Return val + 10
        Else
             Return Nothing
        End If
End Function
您可能需要使用所使用的类型(Object和Integer的Nullable可能不适合您)

然后,当然,在表达式中使用MyAdd并传递ReportItems!FooBox.Value作为参数

可能与我投票关闭的问题重复:你的问题本质上与之前提出的其他几个问题重复。另一个答案: