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

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Handle Divide by Zero in SQL Reporting Services

By Clayton Groom,

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: 3596 | Views in the last 30 days: 9
 
Related Articles
FORUM

Field Explorar like Crystal Report

Field Explorar like Crystal Report

ARTICLE

Using Lookup Function to Bridge Datasets in Report Builder

The report function, lookup, can be used to link two independent datesets.

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

 
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