Friday, July 9, 2010

Writing Custom functions in SSRS

We all know the fact that SSRS comes with very limited system defined functions and most of the times we get into situation where we don't find functions as per our requirement and need.

Many times we come across situation where we want to modify/transform the actual data before rendering it in the report. This transformation can be as simple as changing the date formats and some times it can be complex, such as encoding/decoding of the data stored.
Though we can do these transformation in SQL queries, it is not advisable to do so. Business logic should not be combined with the data layer. So what we should do in situations where SSRS fails to provide you system functions to fulfill your needs ?

Fortunately SSRS allows you to create your own custom functions as per your need. You can create your own custom functions to implement any complex string manipulation/logic using C# or VB.

Recently I had need to decode the HTML contents which are stored in database and show them in the report. As there is no predefined function available to decode encoded HTML, i decided to write my own custom function. Its simple to add a custom function.
Go to Report Properties under report menu. Click on the Code option in right side menu of the popup. It gives you place holder for placing your custom code as shown in below image.














Thats it, you are done. And its also easy to use these custom functions in report. All you need to do is this
Code.HTMLDecode(Fields!Description) in case mentioned above.


cheers,