SSRS expression replace NULL with another field value

半世苍凉 提交于 2019-12-17 17:48:07

问题


I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?


回答1:


=iif(isNothing(Fields!FV1.Value), Fields!FV2.Value, Fields!FV1.Value)



回答2:


If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:

  1. Right click on the Report Document and go to Report Properties.

  2. Navigate to the Code tab and add the following function:

    Public Function IsNull(input As Object, defaultValue As Object) As Object
      Return IIf(input Is Nothing, defaultValue, input)
    End Function
    


    Note - Even though the custom code is expecting valid VB.NET code, you have to use the IIF Ternary operator.
  3. Then you can use it in an expression like this:

    =Code.IsNull(Fields!MyField.Value,0)
    



来源:https://stackoverflow.com/questions/19234993/ssrs-expression-replace-null-with-another-field-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!