SSRS (SQL Server Reporting Services) – Manage custom code in SSRS - Part 3


I explained about Creating Reports and Expressions in Part 1 and 2 respectively. Here, I would like explain about how to create your own custom code or function with parameters. We can call these custome codes through Edit Expression windows of each fields in the SSRS Reports.

SSRS (SQL Server Reporting Services) – Manages custom codes in SSRS



Managing Custom/Embed Codes in SSRS (SQL Server Reporting Services)



Even though, SSRS having lot of built-in functions as we discusses above, we write our custom codes here. These code should be written in Visual Basic only. And also, we can use display constant value. You must write the code inside a public, shared function. Then only, you can catch out these results in your reports. You need to pass values from the report into your function to perform calculations.

Creating our own custom Codes



Right click on empty page of your report and select properties from that showing menu and it show Report Properties Dialog Box.

Click Code tab and write your all your variables and functions.



Public Const MyNote = "Authored by Prabu Thangavelu"

public shared function setColor(byval value as integer) as string

if value < 10 then
return "red"
else if value > 10 and value < 220 then
return "white"
else
return "green"
end if

end function



code1

Call our custom Codes in report



Place a textbox in report and right click on that textbox and select expression and it shows Edit Expression Dialog Box. Write following code in that Dialog Box.

Click Preview and you can see how it shows results.



=code.MyNote



code2



=code.setcolor(Fields!EmployeeID.Value)



code3

Here, you should be careful in one thing, that is, the report should be designed and connected with databases. Then only you can pass integer values for that function.

Click Preview and enjoy your results.


Reference: http://www.dotnetspider.com/resources/42919-SSRS-Implementing-Stored-Procedures-passing.aspx


Related Articles

Comments

Guest Author: Yuvarani24 May 2012

thanks a lot.. saved lot of time ..



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: