ssrs
  1. ssrs-custom-assemblies

Custom Assemblies

Custom assemblies are assemblies that contain code that you can use in your report. These assemblies allow you to extend the functionality of your reports beyond what is available out of the box with SQL Server Reporting Services (SSRS). You can create custom assemblies in .NET languages such as C# or VB.NET and use them in your reports.

Syntax

The syntax for using custom assemblies in SSRS is as follows:

=Code.[FunctionName]()

Example

Consider the following example where we want to create a custom function in a .NET assembly that calculates the distance between two points using the Haversine formula:

using System;

public class Haversine
{
    static double Distance(double lat1, double lon1, double lat2, double lon2)
    {
        double R = 6371; // Earth’s radius in km

        double dLat = (lat2 - lat1) * Math.PI / 180;
        double dLon = (lon2 - lon1) * Math.PI / 180;

        double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                   Math.Cos(lat1 * Math.PI / 180) * Math.Cos(lat2 * Math.PI / 180) *
                   Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
        double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
        double d = R * c;

        return d;
    }
}

We can then compile this code into a .NET assembly and add a reference to it in our SSRS report. We can then use the following expression in a text box to calculate the distance between two points:

=aversine.Distance(40.748817, -73.985428, 41.850030, -87.650050)

This will return the distance in kilometers between New York City and Chicago.

Explanation

In the example above, we create a custom function called Distance in a .NET assembly called Haversine. This function uses the Haversine formula to calculate the distance between two points given their latitude and longitude coordinates. We then add a reference to this assembly in our SSRS report and use the Code object to call the function in an expression.

Use

Custom assemblies can be used in SSRS to extend the functionality of your reports beyond what is available out of the box. You can create custom functions to perform complex calculations, manipulate data in unique ways, or draw custom graphics and visualizations.

Important Points

  • Custom assemblies can be created in .NET languages such as C# or VB.NET.
  • You need to add a reference to the compiled assembly to use it in your SSRS report.
  • You can call custom functions in expressions using the Code object.

Summary

Custom assemblies are a powerful feature of SSRS that allow you to extend the functionality of your reports beyond what is available out of the box. You can create custom functions in .NET languages, compile them into assemblies, and then add a reference to those assemblies in your report. These functions can be used to perform complex calculations, manipulate data in unique ways, or draw custom graphics and visualizations.

Published on: