Click here to Skip to main content
13,736,502 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.5K views
1 bookmarked
Posted 15 Jun 2015
Licenced CPOL

Handling No Data in SSRS Controls

, 15 Jun 2015
Rate this:
Please Sign up or sign in to vote.
Some SSRS controls, such as charts, that reference NoDataMessage property have by default the “No Data Available” caption to handle instances whereby an empty result set is returned.

When SQL Server Reporting Services (SSRS) successfully renders a given report control (i.e., Table, Matrix, List, etc.), the result set can either be empty (which means no data returned) or actually show data. In cases whereby an empty result set is returned, SSRS controls, such as tables and charts, use NoDataMessage and NoRowsMessage properties to inform report users of no data.

Fortunately, some SSRS controls, such as charts, that reference NoDataMessage property have by default the “No Data Available” caption to handle instances whereby an empty result set is returned. To illustrate this point – I have an SSRS dataset in my report that sources HumanResources.vEmployee object from the AdventureWorks2012 Sample Database. I have also created another dataset that will be used to populate report country parameter.

report main dataset

SELECT
    [BusinessEntityID]
    ,[FirstName]
    ,[LastName]
    ,[JobTitle]
    ,[PhoneNumberType]
    ,[City]
    ,[StateProvinceName]
    ,[CountryRegionName]
FROM [AdventureWorks2012].[HumanResources].[vEmployee]

country parameter dataset

SELECT 'Australia' Country
UNION
SELECT 'Canada'
UNION
SELECT 'Germany'
UNION
SELECT 'France'
UNION
SELECT 'United Kingdom'
UNION
SELECT 'United States'
UNION
SELECT 'South Africa'

NoDataMessage Property

I have used aforementioned datasets to add a vertical bar chart in the report that shows a number of Adventure Works employees by country of origin. By default, the report looks as follows:

Default Report View With All Countries Selected

As shown in the above chart, United States has the most number of employees working for Adventure Works. The following images show the report filtered by France and later by South Africa. Whilst a single French employee is found, there are no South African employees and thus the “No Data Available” message is shown.

Report Filtered by France

Report Filtered by South Africa – No Data Available

s8

NoRowsMessage Property

Unlike controls that reference NoDataMessage property, SSRS controls that handle empty result sets using the NoRowsMessage property – do not have a default caption. To illustrate this point, we again use the dataset that determine the number of Adventure Works employees by country of origin, however, instead of a using a chart control, we will display result into a table.

Table Based Off All Countries

Again, when we filter the report by France – we are able to find the single French employee.

Table Filtered by France

Table filtered by South Africa

s13

When the report is filtered by South Africa, as shown below, no data is found – however, unlike the chart control, the “No Data Available” caption is not shown in the table. We could fix this by editing the value of NoRowsMessage property. This is done by:

Step 1

Highlight the Tablix and view its properties.

Report Tablix and its properties

Step 2

Set the NoRowsMessage to “Sorry, No Data”.

Setting value of the NoRowsMessage property

s16

Step 3 (Optional)

Set the Color property to Red.

Setting Value of Color Property to Red

s17

When you rerun the report by using South Africa as a filter, you should be able to see the custom no data message as shown below:

Report Table Control with a Custom No Data Message

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sifiso W Ndlovu
Technical Lead select SIFISO
South Africa South Africa
Sifiso W. Ndlovu is a certified Microsoft professional who holds a Master’s degree in IT Management from the University of Johannesburg. He specializes on a range of enterprise and consumer technologies using open source and proprietary software. He is the member of the Johannesburg SQL User Group wherein he has made several presentations on User Group Meetings and SQL Saturday sessions. He has written for a number of publications including SQLShack.com and SQLServerCentral.com.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.180920.1 | Last Updated 15 Jun 2015
Article Copyright 2015 by Sifiso W Ndlovu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid