BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
Posted by Andy Brown on 21 June 2012
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
SQL Server Reporting Services Variables
Have you ever wondered why SSRS (as I'll call SQL Server Reporting Services from now on) includes a tab for Variables?
You can create variables either for a report or for a group.
Me too! So I thought I'd do an in-depth blog on how - and why - you would use variables in Reporting Services (and in the process unearth one of the odder bugs).
Scope of Variables
I thought I'd start with an explanation of what variables are, which is simply expressions with wider scope than would be the case for a textbox.
To prove this, I've created an example report, which you can download:
The ticks are different at report, group and detail level.
The expression to display the ticks is as follows:
What this does is take the current state of a computer's clock cycle, and extract some digits from it to give an impression of how much time has elapsed. If you look at the figures, you'll see the following:
|Scope of expression||Value of ticks||Calculated|
|Report (appears in report title)||221,463||When the report first loads|
|Group (appears in group footer)||221,744 for visible groups||When each group first loads|
|Detail (6 films are visible)||221,775 and 221, 791||When a page loads|
Versions of Reporting Services from 2008 onwards calculate textbox expressions afresh for every page as it loads, but variables are evaluated once only for the report (and cached in memory). This means that group and report variables can save you a lot of processing time.
Now that we know how variables work, let's look at how you might use them, using one example each for report and group variables.