Free - Reporting on Hierarchical Recursive data using MS Reporting Services

I will start with a question here.  How many of you had chance to interact with Employee table from sample database Northwind?  There you go… I can imagine countless hands in air, and why not it is one of the standard databases comes with both Access and SQL server.  All right, are we going to discuses Northwind database here? NO. Is Employee table is something special? I would say YES to this.  Why special? Well, if you pay a close attention, it is just like any other standard table, however, two fields from the table, “EmployeeID” and “ReportsTo” are related to each other in an interesting way! Yes, you got it right; I am talking about Hierarchical relationship which we also call commonly as Recursive data.  I am trying to shade some light on reporting of data which is recursive in nature.

 

 

 

Overview

What is Recursive Data?

I am sure you must have come face to face with this challenge called Recursive Data if you have to deal with databases.  Hierarchical data which defines the level of association with a defined relationship ca be called recursive in nature.  A typical example would be to take Accounting Application Database which has a table called ChartOfAccounts, the Primary Key “Account_Id” will have foreign key relationship with another column called “Reporting_Account_Id”.  Another example is the one which I am using in this article is that each Employee has a Manager assigned.

Introduction

I will start with a question here.  How many of you had chance to interact with Employee table from sample database Northwind?  There you go… I can imagine countless hands in air, and why not it is one of the standard databases comes with both Access and SQL server.  All right, are we going to discuses Northwind database here? NO. Is Employee table is something special? I would say YES to this.  Why special? Well, if you pay a close attention, it is just like any other standard table, however, two fields from the table, "EmployeeID" and "ReportsTo" are related to each other in an interesting way! Yes, you got it right; I am talking about Hierarchical relationship which we also call commonly as Recursive data.  I am trying to shade some light on reporting of data which is recursive in nature.

What is Recursive Data?

I am sure you must have come face to face with this challenge called Recursive Data if you have to deal with databases.  Hierarchical data which defines the level of association with a defined relationship ca be called recursive in nature.  A typical example would be to take Accounting Application Database which has a table called ChartOfAccounts, the Primary Key "Account_Id" will have foreign key relationship with another column called "Reporting_Account_Id".  Another example is the one which I am using in this article is that each Employee has a Manager assigned.

Do you recall "Self-Join"? As you can see in above image, this is one way we display the recursive nature of data, just putting here for some better understanding.

Reporting Challenge for Recursive Data

I am ready with my second question here, before I ask you; I would like your kind attention to the image with Employee level output. Now the question: Do you think generating report like that without any custom code is piece of cake?  I am pretty sure this time I will see many less hands in air compare to my first question! Or you can say yes it is piece of cake if you have already tried your hands on MS Reporting Services.

It is very common that when we have to deal with a situation like this, we do end up writing some sort of custom code in order to find out the level of hierarchy etc. etc.  A typical developer mindset will always have endless list of wishes for software vendors, one of my wish was if something was done to address this issue of handling recursive data built right into the reporting engine.  Some how I felt my telepathy worked and guys at Microsoft put this feature into reporting services and here I am acknowledging them by writing few lines here.  Though, I would like to clarify one point here,  I have worked with several other reporting engines and did enjoyed them, however, since I started to work with Reporting Services, I personally felt much at ease.

Asif Sayed

I started to code in 1990 using C and GW basic, then moved to 4GL world with DBIII, Clipper and FoxPro etc. and continued till I found and hooked to MS goody bag Visual Basic. For last four years, I am working extensively on .NET technologies and scripting both VB.NET and C#. My ideal choice of database is SQL Server; however, I do interact with Oracle when required. I have worked on all sort of Business applications, but my ideal project would be anything which has some Financial part associated with it, I wish I can put a Balance-sheet report in all the project I do… I also teach .NET related technologies as part-time faculty with local community college and try to help share my knowledge with others.

See All Postings From Asif Sayed >>

Reviews

Be the first to write a review

You must me logged in to write a review.