[转]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 ...
随机推荐
- Devexpress Winform初学笔记
作为一个软件开发人员来说,得有自己的博客,可以用来ZB,哈哈!玩笑话..... 写博客并不仅仅是用来ZB的,他可以用来记录你在技术道路上探索遇到的坎,当然也有提高逼格的次然因素啦!小弟刚入博客园不久, ...
- 【cocos2d-x 环境配置-Mac配置篇】
目前我配置的环境需求如下: JDK 1.6 XCode Version 4.6 (4H127) Cocos2d-x 2.2.0 Android Developer 一,下载安装 要配置环境一次性下 ...
- iOS 内嵌 View 的响应
遇到一个问题就是我有一个 UITextField,点击后不能编辑而是会显示一个自定义的 dialog. 但发现问题是,UITextField 的对点击事件的反应非常吃顿,有时候好使有时候不好使. 后来 ...
- util.Date转化成sql.date格式
https://www.cnblogs.com/zhaotiancheng/p/6413067.html
- 【QT】二进制读取图像文件并显示
打开对话框选择文件 二进制方式读取文件 转换成图像显示 void MainWindow::showImage() { //打开文件对话框 QString lastPath="D:/Engli ...
- Python脱产8期 Day15 2019/4/30
一 生成器send方法 1.send的工作原理# 1.send发生信息给当前停止的yield# 2.再去调用__next__()方法,生成器接着往下指向,返回下一个yield值并停止 2.例: per ...
- javascript学习日记1
1.JavaScript:写入 HTML 输出 document.write("<h1>This is a heading</h1>"); document ...
- UnSafe类中的一些重要方法
UnSafe类中的一些重要方法 JDK中的rt.jar保重Unsafe类中提供了硬件级别的原子性操作,Unsafe类中的方法都是navtice方法,他们使用JNI的方式访问C++实现库,下面我们来了解 ...
- bzoj1047理想的正方形
题目链接 纪念又双叒叕的一道暴力碾标算的题 我们考虑纯暴力 #include<iostream> #include<cstdio> #include<algorithm& ...
- Spring Boot 笔记汇总
使用IDEA搭建Spring Boot入门项目 从零开始完整搭建 Spring-Boot 项目开发框架的教程 IDEA通过Maven WebApp archetype 创建Spring boot项目骨 ...