<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>The Wit and Ramblings of David Giard - SSRS</title>
    <link>http://www.davidgiard.com/</link>
    <description>Demanding rigidly defined areas of doubt and uncertainty</description>
    <language>en-us</language>
    <copyright>David Giard</copyright>
    <lastBuildDate>Tue, 11 Sep 2012 21:20:41 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>davidgiard@davidgiard.com</managingEditor>
    <webMaster>davidgiard@davidgiard.com</webMaster>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=818220a7-cbae-4047-8788-aca3d18d1300</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=818220a7-cbae-4047-8788-aca3d18d1300</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week, I demonstrated how <a href="http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx" target="_blank">to
embed code directly into a SQL Server Reporting Service (SSRS) report</a>.
</p>
        <p>
In this article, I will explain how to reference code in an external assembly from
an SSRS report. The basic steps are
</p>
        <ol>
          <li>
Create External Code</li>
          <li>
Create Unit Tests 
</li>
          <li>
Deploy the assembly to the Report Server</li>
          <li>
Add a reference to the assembly</li>
          <li>
Call external functions in Expression Editor</li>
          <li>
Deploy Report</li>
        </ol>
        <h3>Create External Code
</h3>
        <p>
The first step is to create and compile the external code. The project type will be
a Class Library and you will add a public class with a public static method. This
code can be in C#, Visual Basic, or F#. 
<br />
A sample is shown below in Listing 1. 
</p>
        <p>
        </p>
        <pre class="csharpcode">
          <span class="kwrd">using</span> System; <span class="kwrd">namespace</span> ReportFunctions
{ <span class="kwrd">public</span><span class="kwrd">class</span> ReportLib { <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">string</span> FormatAs2Digits(<span class="kwrd">decimal</span>?
input) { <span class="kwrd">if</span> (input == <span class="kwrd">null</span>) <span class="kwrd">return</span><span class="str">"N/A"</span>; <span class="kwrd">else</span><span class="kwrd">return</span> String.Format(<span class="str">"{0:##,##0.00;(##,##0.00)}"</span>,
input); } } }</pre>
Listing 1
<p>
Compile this code in Release mode
</p><h3>Create Unit Tests
</h3><p>
It's a good idea to create unit tests around this code because it can be difficult
to test it on the Report Server. 
<br />
At a minimum, write tests that mimic how you expect to call the function within your
reports.
</p><h3>Deploy Assembly to Report Server
</h3><p>
In order to use the functions, you must deploy the compiled DLL to the report server.
You can either create a Setup  project to create an MSI package or you can simply
copy the DLL to the drive where SQL Server Reporting Services is installed in the
following folder on the SQL Server installation drive:
</p><blockquote><p>
\Program Files\Microsoft SQL Server\<em>Instance_Name</em>\Reporting Services\ReportServer\bin
</p></blockquote><p>
where <em>Instance_Name </em>is the name of the instance of SQL Server on which SSRS
is running.
</p><h3>Add a reference to the assembly
</h3><p>
Open your Report project and open the report that will call the custom function. From
the menu, select <font face="Courier New">Report | Report Properties</font>. Select
the <em>References </em>tab (Fig. 1). 
</p><p><img src="http://davidgiard.com/content/binary/ssrs/Fig1-ReferencesTab.PNG" /><br /><font size="1">Fig. 1 – “Reference” tab of Report Properties</font></p><p>
Browse to select the deployed assembly containing the code you want to call.
</p><p>
After adding the reference, you will need to compile the Report project before you 
can use the assembly functions. To compile the report, select <font face="Courier New">Buld
| Build Solution</font> from the menu.
</p><h3>Call external functions in Expression Editor
</h3><p>
Open an expression editor and call a function in the external assembly. You will need
to include the entire namespace and classname. In our example, this be
</p><p>
An example is shown in Fig. 2.
</p><p><img src="http://davidgiard.com/content/binary/ssrs/Fig2-ExpressionEditor-External.PNG" /><br /><font size="1">Fig. 2 – Expression Editor</font></p><p>
You can test that the expression works by clicking the Preview tab of the report.
</p><h3>Deploy Report
</h3><p>
The final step is to deploy the report. Assuming you have permissions on the Report
Server and the report sever is set in the project properties, the easiest way to deploy
is to right-click the report in the Solution Explorer and select Deploy.
</p><p>
Now you can test the report and the function on the Report Server.
</p><h3>Conclusion
</h3><p>
In this article, we described how to call code in an external assembly from a SQL
Server Reporting Services report.
</p><img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=818220a7-cbae-4047-8788-aca3d18d1300" /></body>
      <title>Calling an External Assembly from SSRS</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</guid>
      <link>http://www.davidgiard.com/2012/09/11/CallingAnExternalAssemblyFromSSRS.aspx</link>
      <pubDate>Tue, 11 Sep 2012 21:20:41 GMT</pubDate>
      <description>&lt;p&gt;
Last week, I demonstrated how &lt;a href="http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx" target="_blank"&gt;to
embed code directly into a SQL Server Reporting Service (SSRS) report&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
In this article, I will explain how to reference code in an external assembly from
an SSRS report. The basic steps are
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Create External Code&lt;/li&gt;
&lt;li&gt;
Create Unit Tests 
&lt;/li&gt;
&lt;li&gt;
Deploy the assembly to the Report Server&lt;/li&gt;
&lt;li&gt;
Add a reference to the assembly&lt;/li&gt;
&lt;li&gt;
Call external functions in Expression Editor&lt;/li&gt;
&lt;li&gt;
Deploy Report&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Create External Code
&lt;/h3&gt;
&lt;p&gt;
The first step is to create and compile the external code. The project type will be
a Class Library and you will add a public class with a public static method. This
code can be in C#, Visual Basic, or F#. 
&lt;br /&gt;
A sample is shown below in Listing 1. 
&lt;/p&gt;
&lt;p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; ReportFunctions
{ &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ReportLib { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FormatAs2Digits(&lt;span class="kwrd"&gt;decimal&lt;/span&gt;?
input) { &lt;span class="kwrd"&gt;if&lt;/span&gt; (input == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;N/A&amp;quot;&lt;/span&gt;; &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; String.Format(&lt;span class="str"&gt;&amp;quot;{0:##,##0.00;(##,##0.00)}&amp;quot;&lt;/span&gt;,
input); } } }&lt;/pre&gt;
Listing 1&gt;
&lt;p&gt;
Compile this code in Release mode
&lt;/p&gt;
&lt;h3&gt;Create Unit Tests
&lt;/h3&gt;
&lt;p&gt;
It's a good idea to create unit tests around this code because it can be difficult
to test it on the Report Server. 
&lt;br /&gt;
At a minimum, write tests that mimic how you expect to call the function within your
reports.
&lt;/p&gt;
&lt;h3&gt;Deploy Assembly to Report Server
&lt;/h3&gt;
&lt;p&gt;
In order to use the functions, you must deploy the compiled DLL to the report server.
You can either create a Setup&amp;#160; project to create an MSI package or you can simply
copy the DLL to the drive where SQL Server Reporting Services is installed in the
following folder on the SQL Server installation drive:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
\Program Files\Microsoft SQL Server\&lt;em&gt;Instance_Name&lt;/em&gt;\Reporting Services\ReportServer\bin
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
where &lt;em&gt;Instance_Name &lt;/em&gt;is the name of the instance of SQL Server on which SSRS
is running.
&lt;/p&gt;
&lt;h3&gt;Add a reference to the assembly
&lt;/h3&gt;
&lt;p&gt;
Open your Report project and open the report that will call the custom function. From
the menu, select &lt;font face="Courier New"&gt;Report | Report Properties&lt;/font&gt;. Select
the &lt;em&gt;References &lt;/em&gt;tab (Fig. 1). 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig1-ReferencesTab.PNG" /&gt; 
&lt;br /&gt;
&lt;font size="1"&gt;Fig. 1 – “Reference” tab of Report Properties&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Browse to select the deployed assembly containing the code you want to call.
&lt;/p&gt;
&lt;p&gt;
After adding the reference, you will need to compile the Report project before you&amp;#160;
can use the assembly functions. To compile the report, select &lt;font face="Courier New"&gt;Buld
| Build Solution&lt;/font&gt; from the menu.
&lt;/p&gt;
&lt;h3&gt;Call external functions in Expression Editor
&lt;/h3&gt;
&lt;p&gt;
Open an expression editor and call a function in the external assembly. You will need
to include the entire namespace and classname. In our example, this be
&lt;/p&gt;
&lt;p&gt;
An example is shown in Fig. 2.
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig2-ExpressionEditor-External.PNG" /&gt; 
&lt;br /&gt;
&lt;font size="1"&gt;Fig. 2 – Expression Editor&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
You can test that the expression works by clicking the Preview tab of the report.
&lt;/p&gt;
&lt;h3&gt;Deploy Report
&lt;/h3&gt;
&lt;p&gt;
The final step is to deploy the report. Assuming you have permissions on the Report
Server and the report sever is set in the project properties, the easiest way to deploy
is to right-click the report in the Solution Explorer and select Deploy.
&lt;/p&gt;
&lt;p&gt;
Now you can test the report and the function on the Report Server.
&lt;/p&gt;
&lt;h3&gt;Conclusion
&lt;/h3&gt;
&lt;p&gt;
In this article, we described how to call code in an external assembly from a SQL
Server Reporting Services report.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=818220a7-cbae-4047-8788-aca3d18d1300" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,818220a7-cbae-4047-8788-aca3d18d1300.aspx</comments>
      <category>.Net</category>
      <category>SQL Server</category>
      <category>SSRS</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f092759b-06b9-4e82-bbbd-f3aa2e72d43d</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f092759b-06b9-4e82-bbbd-f3aa2e72d43d</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes I find myself applying the same formatting or performing the same task to
many elements within a SQL Server Reporting Services (SSRS) report.
</p>
        <p>
When this happens, I consider writing a reusable function to perform this task or
formatting. Functions can be added directly to an SSRS report.
</p>
        <p>
To add code to an SSRS report, open the report and select Report | Report Properties
from the menu. The <em>Report Properties </em>dialog displays. Select the Code tab
to bring this tab forward (Fig. 1). 
</p>
        <p>
          <img src="http://davidgiard.com/content/binary/ssrs/Fig1-SsrsCodeTab.PNG" />
          <br />
          <strong>
            <font size="1">Fig 1: The Code tab of the SSRS Report Properties dialogue</font>
          </strong>
        </p>
        <p>
This tab contains a single edit box into which you can type Visual Basic code. The
editor is very limited in that you can only use Visual Basic (no C#, F#, or JavaScript),
and it provides no IntelliSense. Still, it does allow you to create functions that
can be called elsewhere within your report. Type your function within this edit box. 
</p>
        <p>
Note: If, like me, you are having trouble writing valid code with the IntelliSense
or other syntax-checking, It might be helpful to create a console application in Visual
Studio and type the same function in order to validate the function's syntax and functionality.
</p>
        <p>
In SSRS, you assign an expression to an object’s property using the Expression Editor
(Fig. 2)
</p>
        <p>
          <img src="http://davidgiard.com/content/binary/ssrs/Fig2-SsrsExpressionEditor.PNG" />
          <br />
          <strong>
            <font size="1">Fig2: The SSRS Expression Editor</font>
          </strong>
        </p>
        <p>
In an Expression editor of any object on the report, you can call the function with
the word "Code", followed by ".", followed by the name of the
function.
</p>
        <p>
For example, I found that I had a number of textboxes that displayed numeric data.
I wanted every number to display with the following rules:
</p>
        <ul>
          <li>
Format the numeric output so exactly 2 digits appear to the right of the decimal point 
</li>
          <li>
Print "N/A" for null values. 
</li>
        </ul>
        <p>
I could accomplish this by doing the following:
</p>
        <ol>
          <li>
Set the formatting of every textbox to "##,##0.00;(##,##0.00)"</li>
          <li>
Change the expression in each textbox to something like: 
<br />
=Iif(IsNothing (Fields!Price), "N/A", Fields!Price)</li>
        </ol>
        <p>
But this is inefficient because one needs to perform the above steps for every textbox
where this change is needed. 
</p>
        <p>
Instead, I created the following function and embedded it into the report:
</p>
        <pre class="csharpcode">
          <span class="kwrd">Public</span>
          <span class="kwrd">Shared</span>
          <span class="kwrd">Function</span> FormatAs2Digits(<span class="kwrd">ByVal</span> input <span class="kwrd">as</span> Nullable(
of <span class="kwrd">decimal</span>)) <span class="kwrd">as</span><span class="kwrd">string</span><span class="kwrd">return</span> Iif(IsNothing
(input), <span class="str">"N/A"</span>, Format(input, <span class="str">"##,##0.00;(##,##0.00)"</span>)) <span class="kwrd">End</span> Function</pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
Then, I could set the expression of each textbox to something similar to the following
</p>
        <pre class="csharpcode">=Code.FormatAs2Digits(Fields!Price)</pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
Be aware that your report runs under a specific user context and that user will likely
have very limited access rights, so your functions will be limited in what that user
context can do. Generally, I only use functions to format data and perform other tasks
encapsulated within the report.
</p>
        <p>
Despite its limitations, an embedded function is an excellent way to create reusable
code and consume it in multiple objects within an SSRS report.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f092759b-06b9-4e82-bbbd-f3aa2e72d43d" />
      </body>
      <title>Embedded Code in an SSRS Report</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</guid>
      <link>http://www.davidgiard.com/2012/09/07/EmbeddedCodeInAnSSRSReport.aspx</link>
      <pubDate>Fri, 07 Sep 2012 20:19:29 GMT</pubDate>
      <description>&lt;p&gt;
Sometimes I find myself applying the same formatting or performing the same task to
many elements within a SQL Server Reporting Services (SSRS) report.
&lt;/p&gt;
&lt;p&gt;
When this happens, I consider writing a reusable function to perform this task or
formatting. Functions can be added directly to an SSRS report.
&lt;/p&gt;
&lt;p&gt;
To add code to an SSRS report, open the report and select Report | Report Properties
from the menu. The &lt;em&gt;Report Properties &lt;/em&gt;dialog displays. Select the Code tab
to bring this tab forward (Fig. 1). 
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig1-SsrsCodeTab.PNG" /&gt; 
&lt;br /&gt;
&lt;strong&gt;&lt;font size="1"&gt;Fig 1: The Code tab of the SSRS Report Properties dialogue&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
This tab contains a single edit box into which you can type Visual Basic code. The
editor is very limited in that you can only use Visual Basic (no C#, F#, or JavaScript),
and it provides no IntelliSense. Still, it does allow you to create functions that
can be called elsewhere within your report. Type your function within this edit box. 
&lt;/p&gt;
&lt;p&gt;
Note: If, like me, you are having trouble writing valid code with the IntelliSense
or other syntax-checking, It might be helpful to create a console application in Visual
Studio and type the same function in order to validate the function's syntax and functionality.
&lt;/p&gt;
&lt;p&gt;
In SSRS, you assign an expression to an object’s property using the Expression Editor
(Fig. 2)
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://davidgiard.com/content/binary/ssrs/Fig2-SsrsExpressionEditor.PNG" /&gt; 
&lt;br /&gt;
&lt;strong&gt;&lt;font size="1"&gt;Fig2: The SSRS Expression Editor&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In an Expression editor of any object on the report, you can call the function with
the word &amp;quot;Code&amp;quot;, followed by &amp;quot;.&amp;quot;, followed by the name of the
function.
&lt;/p&gt;
&lt;p&gt;
For example, I found that I had a number of textboxes that displayed numeric data.
I wanted every number to display with the following rules:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Format the numeric output so exactly 2 digits appear to the right of the decimal point 
&lt;/li&gt;
&lt;li&gt;
Print &amp;quot;N/A&amp;quot; for null values. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I could accomplish this by doing the following:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Set the formatting of every textbox to &amp;quot;##,##0.00;(##,##0.00)&amp;quot;&lt;/li&gt;
&lt;li&gt;
Change the expression in each textbox to something like: 
&lt;br /&gt;
=Iif(IsNothing (Fields!Price), &amp;quot;N/A&amp;quot;, Fields!Price)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
But this is inefficient because one needs to perform the above steps for every textbox
where this change is needed. 
&lt;/p&gt;
&lt;p&gt;
Instead, I created the following function and embedded it into the report:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Shared&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; FormatAs2Digits(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; input &lt;span class="kwrd"&gt;as&lt;/span&gt; Nullable(
of &lt;span class="kwrd"&gt;decimal&lt;/span&gt;)) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; Iif(IsNothing
(input), &lt;span class="str"&gt;&amp;quot;N/A&amp;quot;&lt;/span&gt;, Format(input, &lt;span class="str"&gt;&amp;quot;##,##0.00;(##,##0.00)&amp;quot;&lt;/span&gt;)) &lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Then, I could set the expression of each textbox to something similar to the following
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;=Code.FormatAs2Digits(Fields!Price)&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
Be aware that your report runs under a specific user context and that user will likely
have very limited access rights, so your functions will be limited in what that user
context can do. Generally, I only use functions to format data and perform other tasks
encapsulated within the report.
&lt;/p&gt;
&lt;p&gt;
Despite its limitations, an embedded function is an excellent way to create reusable
code and consume it in multiple objects within an SSRS report.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f092759b-06b9-4e82-bbbd-f3aa2e72d43d" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f092759b-06b9-4e82-bbbd-f3aa2e72d43d.aspx</comments>
      <category>SQL Server</category>
      <category>SSRS</category>
    </item>
  </channel>
</rss>