Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Handle Divide by Zero in SQL Reporting Services

By Clayton Groom, 2006/07/28

Out of the box, Reporting services does not handle divide by zero conditions gracefully.
There are plenty of posting on how to use the IIF() function to accomplish this, with some rather horrific looking code.
In order to simplify the coding process and make the resulting expressions readable by a mere mortal, I wrote the following function that can be included in any report.

Steps:

1. From the menu, choose Report, Report Properties.
2. Click on the Code tab and past the function code into the window.
3. Click on OK

To use the function, you have to reference the code collection in an expression:

=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, Nothing)

Or if you want a zero instead of a blank:

=code.CalcRatio( Fields!PYGrossProfit.Value, Fields!PYSales.Value, 0)



Total article views: 3533 | Views in the last 30 days: 13
 
Related Articles
FORUM

Field Explorar like Crystal Report

Field Explorar like Crystal Report

FORUM

Series Fields in reports

how can Combining series field in a report

FORUM

published reports in production server not functioning

published reports in production server not functioning

FORUM

Use of Split Function in Reports

Use of Split Function in Reports

FORUM

SSRS Matrix reports with Drill down functionality

SSRS Matrix reports with Drill down functionality

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones