Pages

Men

rh

4/28/2012

Using Code element in SSRS Report

In addition to using the standard functions provided with SSRS,  you might want to create your own embedded functions. 

The main advantage of using embedded function is, code are extensibility and reusability. Because the code embedded at the report level can extend the SSRS functions and be reused in any expression of the report.We can write the code in Visual Basic. in addition to custom functions, you can also add custom constraints and variables to your report.
  • To add a code element in the report level, follow the steps:
  • In the Report Designer, click the Design tab.
  • From the Report Menu, select the Report properties to open the Report Properties dialog box.
  • Click the Code Tab
  • Write the function by using Visual Basic code. For example you can define a Custom Color version of your report by using the following code.
function Getstockcolor( ByVal Stock as Short, ByVal  Level as Short) As String
         Dim ReturnValue as String
         RetunValue = " "
         Select  Case (100 * stock)/ Level
                     Case Is < 80
                                ReturnValue = "Red"
                     Case Is  <100
                                Return Value = "Blue"
                     Case Is >=100
                                Return Value = "Green"
          End Select
          Return ReturnValue
 End function    

After you create an Embedded Function, you can use the function, you can use the function in any expression. Use Code Prefix to reference to the function. For example you can use the following function to assign the background color property:
=Code,GetStockColor(fields!Quantity.value, Fields!ReorderPoint.Value)

No comments :

Post a Comment