[转]SSRS: Checking for Divide By Zero Using Custom Code
本文转自:http://salvoz.com/blog/2011/11/25/ssrs-checking-for-divide-by-zero-using-custom-code/
I encountered a divide-by-zero error while working on an SSRS report and thought the issue could easily be resolved using IIF with code similar to the following:
=IIF(Fields!Denominator.Value = 0, 0, Fields!Numerator.Value/Fields!Denominator.Value)
I soon realized that this does not resolve the issue. It appears that all parameters in the IIF function are evaluated regardless if the first parameter evaluates to true or false. Therefore, the divide-by-zero was still occurring.
After doing some research, I decided that the best option to avoid the divide-by-zero error is to implement custom code.
Note: The following screen shots are from Report Builder 3.0
The first step is to open the Report Properties window. You can access the report properties by clicking anywhere outside of the report body.
If you still cannot see the Report Properties window, make sure you have the ‘Properties’ option checked in the ‘View’ tab.
![]()
The Report Properties window is displayed below. In the Code text box, click the ellipse […]. You may need to click on the Code text box first to see the ellipse button.
![]()
Next, select ‘Code’ in the left hand menu if it is not already selected. Paste the code (displayed below screen shot) in the Custom code field.
![]()
Function Divide(Numerator as Double, Denominator as Double) If Denominator = 0 Then Return 0 Else Return Numerator/Denominator End If End Function
Now that you’ve created the custom code, you can begin to use the code in your report. The following is an example of how you can use the Divide function in a text box expression:
=Code.Divide(Fields!CurrentYearSales.Value-Fields!PriorYearSales.Value,Fields!PriorYearSales.Value)*100
[转]SSRS: Checking for Divide By Zero Using Custom Code的更多相关文章
- Integrating .NET Code and SQL Server Reporting Services
SQL Server Reporting Services versions 2000 and 2005 (SSRS) has many powerful features. SSRS has a w ...
- SSRS开发的经验记录
虽然工作经验相当的长,但是之前在SSRS上还没有象今天这样的经验.这只是工作经验的一点记录. 1. 定义DataSet 定义DataSet的时后,可以采用Text的方式.用Text的方式可以用一段比较 ...
- 查找EBS中各种文件版本(Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER)
Finding File Versions in the Oracle Applications EBusiness Suite - Checking the $HEADER (文档 ID 85895 ...
- SSRS 通过Customer Code访问Dataset
A dataset in Reporting Services is not the same type of object as an ADO.Net dataset. A report data ...
- python修饰器各种实用方法
This page is meant to be a central repository of decorator code pieces, whether useful or not <wi ...
- C++ Core Guidelines
C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...
- Android 4 学习(16):Database and Content Providers
参考<Professional Android 4 Development> Database and Content Providers Android Database简介 Andro ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q102-Q104)
Question 102 You are designing a Windows application that accesses information stored on a ShareP ...
- (转载)SQL Reporting Services (Expression Examples)
https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...
随机推荐
- ASP.NET WebAPI 测试文档 (Swagger)
ASP.NET WebAPI使用Swagger生成测试文档 SwaggerUI是一个简单的Restful API测试和文档工具.简单.漂亮.易用(官方demo).通过读取JSON配置显示API .项目 ...
- LESS+to+MCSS
此文已由作者郑海波授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验 一.前言 虽然首页没有开始做,昨天仍决定将[MCSS](https://github.com/NetEaseW ...
- Javascript对象的几种创建方式
(1) 工厂模式 Function(){ Var child = new object() Child.name = “欲泪成雪” Child.age=”20” Return child; } Var ...
- 【Oracle 12c】CUUG OCP认证071考试原题解析(31)
31.choose the best answer Which statement is true regarding the USING clause in table joins? A) It c ...
- P5277 【模板】多项式开根(加强版)(bsgs or Cipolla)
题面 传送门 题解 首先你得会多项式开根->这里 其次你得会解形如 \[x^2\equiv a \pmod{p}\] 的方程 这里有两种方法,一个是\(bsgs\)(这里),还有一种是\(Cip ...
- redis5.0.4-cluster集群搭建及jedis客户端操作
一.去官网下载redis5.0 https://redis.io/download 然后解压安装 $ .tar.gz $ cd redis- $ make 二.准备配置文件 打开redis-5.0.4 ...
- PHP中关于foreach的笔试题
1,php与C++的不同之处是PHP中变量没有局部作用域,只有函数作用域和全局作用域.如下函数,在php中,$name的作用域是函数test():在C++中$name的作用域是for循环体,for循环 ...
- DBHelper--Java JDBC SSH 连接数据库工具类
概述 JDBC 指 Java 数据库连接,是一种标准Java应用编程接口( JAVA API),用来连接 Java 编程语言和广泛的数据库. ----------------------------- ...
- 如何检查 IP是否冲突了
[root@TEST_192_168_1_252 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 44:A8:42:00:1A:B5 ...
- Laravel - 从百草园到三味书屋 "From Apprentice To Artisan"目录
Laravel - 从百草园到三味书屋 "From Apprentice To Artisan"目录 https://my.oschina.net/zgldh/blog/38924 ...