<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data Inspirations &#187; T-SQL Tuesday</title>
	<atom:link href="http://blog.datainspirations.com/tag/tsql-tuessday/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.datainspirations.com</link>
	<description>Inspiring Intelligence from Information</description>
	<lastBuildDate>Thu, 02 Feb 2012 01:12:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Retrieving Aggregate Data from Analysis Services for Reports</title>
		<link>http://blog.datainspirations.com/2011/03/08/retrieving-aggregate-data/</link>
		<comments>http://blog.datainspirations.com/2011/03/08/retrieving-aggregate-data/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 23:40:24 +0000</pubDate>
		<dc:creator>Stacia Misner</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SSAS]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://blog.datainspirations.com/?p=356</guid>
		<description><![CDATA[It’s the second Tuesday of the month, so that means it’s T-SQL Tuesday! This month’s host is Jes Borland (blog &#124; twitter) and the topic is Aggregate Functions. I agree with Doug Lane (blog &#124; twitter), who pointed out in his T-SQL Tuesday post that it’s best if you use the database engine to calculate [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.datainspirations.com/wp-content/uploads/2010/11/1dc72ec994ab_7A55/TSQL2sDay150x150.jpg"><img style="background-image: none; margin: 0px 8px 3px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; padding-top: 0px; border-width: 0px;" title="TSQL2sDay150x150" src="http://blog.datainspirations.com/wp-content/uploads/2010/11/1dc72ec994ab_7A55/TSQL2sDay150x150_thumb.jpg" border="0" alt="TSQL2sDay150x150" width="154" height="154" align="left" /></a>It’s the second Tuesday of the month, so that means it’s T-SQL Tuesday! This month’s host is Jes Borland (<a href="http://blogs.lessthandot.com/index.php/All/?author=420" target="_blank">blog</a> | <a href="http://twitter.com/grrl_geek" target="_blank">twitter</a>) and the topic is <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/come-one-come-all-to" target="_blank">Aggregate Functions</a>.</p>
<p>I agree with Doug Lane (<a href="http://www.douglane.net" target="_blank">blog</a> | <a href="http://twitter.com/douglane4" target="_blank">twitter</a>), <a href="http://www.douglane.net/2011/03/t-sql-tuesday-016-aggregations-in-reporting-services/" target="_blank">who pointed out in his T-SQL Tuesday post</a> that it’s best if you use the database engine to calculate aggregates rather than use aggregate functions in Reporting Services. There are some things the database engine can simply do better, and we should use the best tool for the job. But an even better way to work with aggregated data, in my opinion, is to put data into a cube and let Analysis Services do the calculations. Either way, whether you use a relational source like SQL Server or a multidimensional source like Analysis Services, the point is that the back-end engines will always outperform Reporting Services. On the back-end, Analysis Services should outperform SQL Server if the cube and the report query are both designed properly.</p>
<p>That said, there is some trickiness involved when  retrieving and using aggregations in reports. I was having a déjà vu moment as I was writing this blog and sure enough I found that I had touched on the subject several years ago in my blog post, <a href="http://blog.datainspirations.com/2007/04/04/showing-server-aggregations-in-reporting-services/" target="_blank">Showing Server Aggregations in Reporting Services</a>. The post was written in reference to Reporting Services 2005, but the principles still apply. In today’s post, I’ll revisit the same query but add in some pictures this time to help clarify.</p>
<h5>The Problem</h5>
<p>If I create a table using the query from the referenced post, and if I add a total row using the Reporting Services SUM function, I get this result:</p>
<p><a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix11.png"><img class="alignleft size-full wp-image-359" title="Tablix1" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix11.png" alt="" width="506" height="162" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The SUM function would work just fine if I were to use an additive measure, like SalesAmount, but the SUM function doesn’t work at all with non-additive measures like Gross Profit Margin. It adds up the percentage values to produce the total row value but it really needs to compute the sum of sales and the sum of costs separately and then do the math to compute the correct result.</p>
<h5>The Solution</h5>
<p>Instead of using the SUM function, we can use the AGGREGATE function instead. That is we replace this expression:</p>
<p><span style="font-family: 'Courier New';">=Sum(Fields!Gross_Profit_Margin.Value)</span></p>
<p>with this expression:</p>
<p><span style="font-family: 'Courier New';">=Aggregate(Fields!Gross_Profit_Margin.Value)</span></p>
<h5>Where’s the Value?</h5>
<p>When I make the change to the expression and preview the report, I find that I have a new problem – the total row is now missing a value completely!</p>
<p><a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix1.png"><img title="Tablix1" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix1.png" alt="" width="498" height="162" /></a></p>
<p>&nbsp;</p>
<p>The reason is that the Aggregate function requires me to use a query in design mode only, not in query mode. (At least that’s the case in Reporting Services 2008 R2. I don’t remember that this was true in Reporting Services 2005, but I don’t have an instance for that version handy at the moment to try it out. I think, from reading my prior post, that it worked in either mode, but I can’t prove it at the moment!) In other words, I can’t write the MDX manually in query mode – I must use the drag-and-drop interface to create my query. That’s fine for simple queries, but it won’t work when you need to add in calculations or otherwise make adjustments to the auto-generated query.</p>
<h5>The Complete Solution</h5>
<p>So once I switch the query to design mode like this:</p>
<p><a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/SSASQuery.png"><img class="alignleft size-full wp-image-361" title="SSASQuery" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/SSASQuery.png" alt="" width="443" height="331" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>And then preview the report, I now get the desired result.</p>
<p><a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix3.png"><img class="alignleft size-full wp-image-360" title="Tablix3" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/Tablix3.png" alt="" width="501" height="164" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>As I mentioned above, this will only work when the query is in design more. And there’s another requirement&#8211;the tablix must have at least one group defined. The benefit, though, is a faster report than you’ll get from running a comparable relational query. You won’t notice the difference in the AdventureWorks databases, but in that case, Reporting Services will perform aggregate functions reasonably well anyway. But if your data source has high volumes of data, then using a combination of cubes and Reporting Services will deliver much faster reports.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.datainspirations.com/2011/03/08/retrieving-aggregate-data/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>I Hereby Resolve&#8230; (T-SQL Tuesday #14)</title>
		<link>http://blog.datainspirations.com/2011/01/11/i-hereby-resolve-t-sql-tuesday-14/</link>
		<comments>http://blog.datainspirations.com/2011/01/11/i-hereby-resolve-t-sql-tuesday-14/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 18:14:23 +0000</pubDate>
		<dc:creator>Stacia Misner</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://blog.datainspirations.com/2011/01/11/i-hereby-resolve-t-sql-tuesday-14/</guid>
		<description><![CDATA[It’s time for another T-SQL Tuesday, hosted this month by Jen McCown (blog&#124;twitter), on the topic of resolutions. Specifically, “what techie resolutions have you been pondering, and why?” I like that word – pondering – because I ponder a lot. And while there are many things that I do already because of my job, there [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.datainspirations.com/wp-content/uploads/2010/11/1dc72ec994ab_7A55/TSQL2sDay150x150.jpg"><img style="background-image: none; border-right-width: 0px; margin: 0px 8px 3px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="TSQL2sDay150x150" border="0" alt="TSQL2sDay150x150" align="left" src="http://blog.datainspirations.com/wp-content/uploads/2010/11/1dc72ec994ab_7A55/TSQL2sDay150x150_thumb.jpg" width="154" height="154" /></a>It’s time for another T-SQL Tuesday, hosted this month by Jen McCown (<a href="http://www.midnightdba.com/Jen/" target="_blank">blog</a>|<a href="http://twitter.com/#!/MidnightDBA" target="_blank">twitter</a>), on the topic of resolutions. Specifically, “<a href="http://www.midnightdba.com/Jen/2011/01/tsql-tuesday-014/" target="_blank">what techie resolutions have you been pondering, and why?</a>” I like that word – pondering – because I ponder a lot. And while there are many things that I do already because of my job, there are many more things that I ponder about doing…if only I had the time. Then I ponder about making time, but then it’s back to work! In 2010, I was moderately more successful in making time for things that I ponder about than I had been in years past, and I hope to continue that trend in 2011. If Jen hadn’t settled on this topic, I could keep my ponderings to myself and no one would ever know the outcome, but she’s egged me on (and everyone else that chooses to participate)! So here goes…</p>
<p>For me, having resolve to do something means that I wouldn’t be doing that something as part of my ordinary routine. It takes extra effort to make time for it. It’s not something that I do once and check off a list, but something that I need to commit to over a period of time. So with that in mind, I hereby resolve…</p>
<p><strong>To Learn Something New…</strong></p>
<p>One of the things I love about my job is that I get to do a lot of things outside of my ordinary routine. It’s a veritable smorgasbord of opportunity! So what more could I possibly add to that list of things to do? Well, the more I learn, the more I realize I have so much more to learn. It would be much easier to remain in ignorant bliss, but I was born to learn. Constantly. (And apparently to teach, too– my father will tell you that as a small child, I had the neighborhood kids gathered together to play school – in the summer. I’m sure they loved that – but they did it!) These are some of things that I want to dedicate some time to learning this year:</p>
<ul>
<li><strong>Spatial data</strong>. I have a good understanding of how maps in Reporting Services works, and I can cobble together a simple T-SQL spatial query, but I know I’m only scratching the surface here. Rob Farley (<a href="http://sqlblog.com/blogs/rob_farley/default.aspx" target="_blank">blog</a>|<a href="http://twitter.com/#!/rob_farley" target="_blank">twitter</a>) posted <a href="http://sqlblog.com/blogs/rob_farley/archive/2011/01/04/visually-stunning-maps-and-pivotviewer.aspx" target="_blank">interesting examples of combining maps and PivotViewer</a>, and I think there’s so many more creative possibilities. I’ve always felt that pictures (including charts and maps) really help people get their minds wrapped around data better, and because a lot of data has a geographic aspect to it, I believe developing some expertise here will be beneficial to my work. </li>
<li><strong>PivotViewer</strong>. Not only is <a href="http://www.microsoft.com/silverlight/pivotviewer/" target="_blank">PivotViewer</a> combined with maps a useful way to visualize data, but it’s an interesting way to work with data. If you haven’t seen it yet, check out this <a href="http://netflixpivot.cloudapp.net/" target="_blank">interactive demonstration</a> using <a href="http://developer.netflix.com/docs/oData_Catalog" target="_blank">Netflx OData feed</a>. According to Rob Farley, learning how to work with PivotViewer isn’t trivial. Just the type of challenge I like! </li>
<li><strong>Security</strong>. You’ve heard of the accidental DBA? Well, I am the accidental security person – is there a word for that role? My eyes used to glaze over when having to study about security, or&#160; when reading anything about it. Then I had a problem long ago that no one could figure out – not even the vendor’s tech support – until I rolled up my sleeves and painstakingly worked through the myriad of potential problems to resolve a very thorny security issue. I learned a lot in the process, and have been able to share what I’ve learned with a lot of people. But I’m not convinced their eyes weren’t glazing over, too. I don’t take it personally – it’s just a very dry topic! So in addition to deepening my understanding about security, I want to find a way to make the subject as it relates to SQL Server and business intelligence more accessible and less boring. </li>
</ul>
<p>Well, there’s actually a lot more that I could put on this list, and a lot more things I have plans to do this coming year, but I run the risk of overcommitting myself. And then I wouldn’t have time…</p>
<p><strong>To Have Fun!</strong></p>
<p>My name is Stacia and I’m a workaholic. When I love what I do, it’s difficult to separate out the work time from the fun time. But there are some things that I’ve been meaning to do that aren’t related to business intelligence for which I really need to develop some resolve. And they are techie resolutions, too, in a roundabout sort of way!</p>
<ul>
<li><strong>Photography</strong>. When my husband and I went on an extended camping trip in 2009 to Yellowstone and the Grand Tetons, I had a nice little digital camera that took decent pictures. But then I saw the gorgeous cameras that other tourists were toting around and decided I needed one too. So I bought a Nikon D90 and have started to learn to use it, but I’m definitely still in the beginning stages. I traveled so much in 2010 and worked on two book projects that I didn’t have a lot of free time to devote to it. I was very inspired by Kimberly Tripp’s (<a href="http://www.sqlskills.com/BLOGS/KIMBERLY/" target="_blank">blog</a>|<a href="http://twitter.com/#!/KimberlyLTripp" target="_blank">twitter</a>) and Paul Randal’s (<a href="http://www.sqlskills.com/BLOGS/PAUL/" target="_blank">blog</a>|<a href="http://twitter.com/#!/PaulRandal" target="_blank">twitter</a>) <a href="http://www.sqlskills.com/BLOGS/PAUL/category/Where-In-The-World-Are-Paul-And-Kimberly.aspx" target="_blank">photo-adventure in Alaska</a>, though, and plan to spend some dedicated time with my camera this year. (And hopefully before I move to Alaska – nothing set in stone yet, but we hope to move to a remote location – with Internet access – later this year!) </li>
<li><strong>Astronomy</strong>. I have this cool telescope, but it suffers the same fate as my camera. I have been gone too much and busy with other things that I haven’t had time to work with it. I’ll figure out how it works, and then so much time passes by that I forget how to use it. I have this crazy idea that I can actually put the camera and the telescope together for astrophotography, but I think I need to start simple by learning how to use each component individually. As long as I’m living in Las Vegas, I know I’ll have clear skies for nighttime viewing, but when we move to Alaska, we’ll be living in a rain forest. I have no idea what my opportunities will be like there – except I know that when the sky is clear, it will be far more amazing than anything I can see in Vegas – even out in the desert &#8211; because I’ll be so far away from city light pollution. </li>
</ul>
<p>I’ve been contemplating putting together a blog on these topics as I learn. As many of my fellow bloggers in the SQL Server community know, sometimes the best way to learn something is to sit down and write about it. I’m just stumped by coming up with a clever name for the new blog, which I was thinking about inaugurating with my move to Alaska. Except that I don’t know when that will be exactly, so we’ll just have to wait and see which comes first!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.datainspirations.com/2011/01/11/i-hereby-resolve-t-sql-tuesday-14/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Right-to-Left Foot (T-SQL Tuesday #13)</title>
		<link>http://blog.datainspirations.com/2010/12/14/my-right-to-left-foot-t-sql-tuesday-13/</link>
		<comments>http://blog.datainspirations.com/2010/12/14/my-right-to-left-foot-t-sql-tuesday-13/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 22:40:09 +0000</pubDate>
		<dc:creator>Stacia Misner</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://blog.datainspirations.com/2010/12/14/my-right-to-left-foot-t-sql-tuesday-13/</guid>
		<description><![CDATA[As a business intelligence consultant, I often encounter the situation described in this month&#8217;s T-SQL Tuesday, hosted by Steve Jones ( Blog &#124; Twitter) – “What the Business Says Is Not What the&#160; Business Wants.” Steve posed the question, “What issues have you had in interacting with the business to get your job done?” My [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.datainspirations.com/wp-content/uploads/2010/11/87ca1f0f757e_8617/TSQL2sDay150x150.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="TSQL2sDay150x150" border="0" alt="TSQL2sDay150x150" align="left" src="http://blog.datainspirations.com/wp-content/uploads/2010/11/87ca1f0f757e_8617/TSQL2sDay150x150_thumb.jpg" width="95" height="95" /></a>As a business intelligence consultant, I often encounter the situation described in this month&#8217;s <a href="http://www.sqlservercentral.com/blogs/steve_jones/archive/2010/12/7/t_2D00_sql-tuesday-_2300_13-_2D00_-what-the-business-says-is-not-what-the-business-wants.aspx" target="_blank">T-SQL Tuesday</a>, hosted by Steve Jones ( <a href="http://www.sqlservercentral.com/blogs/steve_jones/default.aspx">Blog </a>| <a href="http://twitter.com/Wayoutwest" target="_blank">Twitter</a>) – “What the Business Says Is Not What the&#160; Business Wants.” Steve posed the question, “What issues have you had in interacting with the business to get your job done?” </p>
<p>My profession requires me to have one foot firmly planted in the technology world and the other foot planted in the business world. I learned long ago that the business never says exactly what the business wants because the business doesn&#8217;t have the words to describe what the business wants accurately enough for IT. Not only do technological-savvy barriers exist, but there are also linguistic barriers between the two worlds. So how do I cope?    </p>
<p>The adage &quot;a picture is worth a thousand words&quot; is particularly helpful when I&#8217;m called in to help design a new business intelligence solution. Many of my students in BI classes have heard me explain (&quot;rant&quot;) about left-to-right versus right-to-left design. To understand what I mean about these two design options, let&#8217;s start with a picture:</p>
<p><a href="http://blog.datainspirations.com/wp-content/uploads/2010/11/87ca1f0f757e_8617/DW.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="DW" border="0" alt="DW" src="http://blog.datainspirations.com/wp-content/uploads/2010/11/87ca1f0f757e_8617/DW_thumb.png" width="244" height="148" /></a>     </p>
<p>When we design a business intelligence solution that includes some sort of traditional data warehouse or data mart design, we typically place the data sources on the left, the new solution in the middle, and the users on the right. When I&#8217;ve been called in to help course-correct a failing BI project, I often find that IT has taken a left-to-right approach. They look at the data sources, decide how to model the BI solution as a _______ (fill in the blank with data warehouse, data mart, cube, etc.), and then build the new data structures and supporting infrastructure. (Sometimes, they actually do this without ever having talked to the business first.) Then, when they show what they&#8217;ve built to the business, the business says that is not what we want. Uh-oh.     </p>
<p>I prefer to take a right-to-left approach. Preferably at the beginning of a project. But even if the project starts left-to-right, I&#8217;ll do my best to swing it around so that we’re back to a right-to-left approach. (When circumstances are beyond my control, I carry on, but it’s a painful project for everyone – not because of me, but because the approach just doesn’t get to what the business wants in the most effective way.) By using a right to left approach, I try to understand what it is the business is trying to accomplish. I do this by having them explain reports to me, and explaining the decision-making process that relates to these reports. Sometimes I have them explain to me their business processes, or better yet show me their business processes in action because I need pictures, too. I (unofficially) call this part of the project &quot;getting inside the business&#8217;s head.&quot; This is starting at the right side of the diagram above.     </p>
<p>My next step is to start moving leftward. I do this by preparing some type of prototype. Depending on the nature of the project, this might mean that I simply mock up some data in a relational database and build a prototype report in Reporting Services. If I&#8217;m lucky, I might be able to use real data in a relational database. I&#8217;ll either use a subset of the data in the prototype report by creating a prototype database to hold the sample data, or select data directly from the source. It all depends on how much data there is, how complex the queries are, and how fast I need to get the prototype completed. </p>
<p>If the solution will include Analysis Services, then I&#8217;ll build a prototype cube. Analysis Services makes it incredibly easy to prototype. You can sit down with the business, show them the prototype, and have a meaningful conversation about what the BI solution should look like. I know I&#8217;ve done a good job on the prototype when I get knocked out of my chair so that the business user can explore the solution further independently. (That&#8217;s really happened to me!) We can talk about dimensions, hierarchies, levels, members, measures, and so on with something tangible to look at and without using those terms. It&#8217;s not helpful to use sample data like Adventure Works or to use BI terms that they don&#8217;t really understand. But when I show them their data using the BI technology and talk to them in their language, then they truly have a picture worth a thousand words. From that, we can fine tune the prototype to move it closer to what they want. They have a better idea of what they&#8217;re getting, and I have a better idea of what to build.    </p>
<p>So right to left design is not truly moving from the right to the left. But it starts from the right and moves towards the middle, and once I know what the middle needs to look like, I can then build from the left to meet in the middle. And that’s how I get past what the business says to what the business wants.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.datainspirations.com/2010/12/14/my-right-to-left-foot-t-sql-tuesday-13/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 R2 Reporting Services &#8211; I&#8217;ve Got Your Page Number (T-SQL Tuesday #005)</title>
		<link>http://blog.datainspirations.com/2010/04/13/ssrs-page-number/</link>
		<comments>http://blog.datainspirations.com/2010/04/13/ssrs-page-number/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 23:13:42 +0000</pubDate>
		<dc:creator>Stacia Misner</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[T-SQL Tuesday]]></category>

		<guid isPermaLink="false">http://blog.datainspirations.com/?p=127</guid>
		<description><![CDATA[As you might have guessed if you&#8217;ve been reading my blog lately, I&#8217;ve been spending a lot of time working with the business intelligence features in SQL Server 2008 R2. Not just Reporting Services, but the whole BI stack. However, it just so happens that today is T-SQL Tuesday and the topic this month is Reporting [...]]]></description>
			<content:encoded><![CDATA[<p>As you might have guessed if you&#8217;ve been reading my blog lately, I&#8217;ve been spending a lot of time working with the business intelligence features in <a title="SQL Server 2008 R2" href="http://www.microsoft.com/sqlserver/2008/en/us/r2.aspx" target="_blank">SQL Server 2008 R2</a>. Not just Reporting Services, but the whole BI stack. However, it just so happens that today is <a href="http://sqlvariant.com/wordpress/index.php/2010/04/t-sql-tuesday-005-reporting/" target="_blank">T-SQL Tuesday</a> and the topic this month is Reporting (hosted by Aaron Nelson &#8211; <a href="http://sqlvariant.com/wordpress/" target="_blank">blog </a>| <a href="http://twitter.com/SQLVariant" target="_blank">twitter</a>) , so I thought I&#8217;d use the opportunity to contribute another observation about new <a title="Using Built-in Globals and Users Field References in Expressions" href="http://technet.microsoft.com/en-us/library/dd255216(SQL.105).aspx">properties and globals</a> that you can find in the upcoming release of Reporting Services. Today, I&#8217;ll explain how you can use the <strong>PageName </strong>and <strong>ResetPageNumber</strong> properties to dynamically change the values of <strong>Globals!PageName </strong>(a new global) and <strong>Globals!PageNumber</strong> (a long-time global) respectively during report execution. And I&#8217;ll introduce <strong>Globals!OverallPageNumber </strong>and <strong>Globals!OverallTotalPages</strong>.</p>
<p>One of the problems that I currently have with earlier versions of Reporting Services is the inability to control page numbering when I use subreports. I have a situation where I have many individual reports that I want to combine into a single PDF document for distribution. Page numbering is available only in the page header or page footer of a report, so I can&#8217;t define the page numbering strategy in the report that I define as a subreport. And even if I could, prior to SQL Server 2008 R2, there was no simple way to renumber pages dynamically within the report. That is, the page numbering applies to the entire report. I cannot number the pages in a distinct section of the report separately from other sections.</p>
<p>With the new version of Reporting Services, I can now solve this problem. Not only can I have separate page numbering by &#8220;section&#8221;, but I can also assign names to each &#8220;section&#8221;. For this example, I&#8217;ve taken a very simple approach to prove out what&#8217;s possible. That means it&#8217;s  not pretty or elegant, or meant to illustrate best practices, but it&#8217;s functional and to the point. Let&#8217;s get started.</p>
<p>The master report contains a Tablix data region which has a PageName property that I can use for naming the first section of my report, as shown in Figure 1. You can use static text, as I have done, or you can use an expression. The <strong>PageName </strong>property is a property of a data region or a group. I haven&#8217;t tested it extensively, but it appears to remain constant from page to page until the report execution renders another data region or group where the <strong>PageName </strong>property is set to a new value.</p>
<div id="attachment_128" class="wp-caption alignnone" style="width: 297px"><a href="http://blog.datainspirations.com/wp-content/uploads/2010/04/PageName1.png"><img class="size-full wp-image-128 " title="PageName property" src="http://blog.datainspirations.com/wp-content/uploads/2010/04/PageName1.png" alt="" width="287" height="153" /></a><p class="wp-caption-text">Figure 1</p></div>
<p>In the report that I&#8217;ll use as a subreport, I set the <strong>PageName </strong>property to <em>Sales Summary</em>, on the outermost tablix. You&#8217;ll see later that this property &#8220;pulls through&#8221; to the rendered report. I can also set page breaks (see Figure 2) on the groups in that report which appear in the rendered report, which I have on the group (which breaks on calendar year) of the outermost tablix. The only thing that I cannot define in this report is page numbering because pagination properties are ignored when a report is used as a subreport. Note that the <strong>PageName </strong>is left blank here. It will continue to use <em>Sales Summary </em>which is defined on the Tablix2 object.</p>
<div id="attachment_129" class="wp-caption alignnone" style="width: 701px"><a href="http://blog.datainspirations.com/wp-content/uploads/2010/04/SubreportPageBreak.png"><img class="size-full wp-image-129 " title="SubreportPageBreak" src="http://blog.datainspirations.com/wp-content/uploads/2010/04/SubreportPageBreak.png" alt="" width="691" height="424" /></a><p class="wp-caption-text">Figure 2</p></div>
<p>Now the problem that I have with subreports is that there is no way for me to tell it to 1) insert a page break before rendering the subreport, and 2) reset the page numbering. However, I can use a rectangle to handle the pagination for me. So I add a rectangle to MasterReport, insert a subreport inside the rectangle, and configure the subreport to point to the ResellerSales report. Next, I configure the pagination properties on the rectangle, as shown in Figure 3. I force a page break with <strong>BreakLocation</strong> = Start, and set <strong>ResetPageNumber</strong> to True.</p>
<div id="attachment_130" class="wp-caption alignnone" style="width: 297px"><a href="http://blog.datainspirations.com/wp-content/uploads/2010/04/RectanglePagination.png"><img class="size-full wp-image-130 " title="RectanglePagination" src="http://blog.datainspirations.com/wp-content/uploads/2010/04/RectanglePagination.png" alt="" width="287" height="180" /></a><p class="wp-caption-text">Figure 3</p></div>
<p>The page number reset applies only to the current page counter. You display the value of the current page counter in the page header or footer by using the <strong>Globals!PageNumber</strong>, which has always been a part of Reporting Services. However, in SSRS 2008 R2, you can now reset the current page counter to zero anytime you want to begin a new page numbering sequence in your report. Meanwhile, you can display the running count of ALL pages in your report by using the new globals, <strong>Globals!OverallPageNumber</strong> and <strong>Globals!OverallTotalPages</strong>. To illustrate the two page counters, I have two textboxes in the page footer of my report (which is the only place you can use the globals related to pagination).</p>
<p>The first expression applies the current section of my report which is affected by the page number reset and displays the value of the PageName property:</p>
<pre>=Globals!PageName + " "  + CStr(Globals!PageNumber) + " of " + CStr(Globals!TotalPages)</pre>
<p>The second expression displays the overall page count, which is unaffected by the page number reset:</p>
<pre>=CStr(Globals!OverallPageNumber) + " of " + CStr(Globals!OverallTotalPages) + " Overall"</pre>
<p>Now when I preview the report, I see the footer shown in Figure 4 on the first page of the report. Here you can see the first &#8220;section&#8221; of the report is a total of 5 pages while the overall report is 9 pages.</p>
<div id="attachment_131" class="wp-caption alignnone" style="width: 628px"><a href="http://blog.datainspirations.com/wp-content/uploads/2010/04/ReportPage1.png"><img class="size-full wp-image-131 " title="ReportPage1" src="http://blog.datainspirations.com/wp-content/uploads/2010/04/ReportPage1.png" alt="" width="618" height="58" /></a><p class="wp-caption-text">Figure 4</p></div>
<p>And then paging forward to the first page of the subreport, I find the footer shown in Figure 5. The <strong>PageName </strong>property of the tablix in the subreport now replaces the prior page name. (Remember that you can use an expression instead of static text.)</p>
<div id="attachment_132" class="wp-caption alignnone" style="width: 628px"><a href="http://blog.datainspirations.com/wp-content/uploads/2010/04/ReportPage2.png"><img class="size-full wp-image-132  " title="ReportPage2" src="http://blog.datainspirations.com/wp-content/uploads/2010/04/ReportPage2.png" alt="" width="618" height="71" /></a><p class="wp-caption-text">Figure 5</p></div>
<p>If you want to take a closer look, you can <a href="http://datainspirations.com/uploads/PageNumbering.zip" target="_blank">download my project</a> and try it out yourself. To execute the report, you must have the <a href="http://msftdbprodsamples.codeplex.com/releases/view/24854" target="_blank">AdventureWorksDW2008R2</a> database installed, and you must download and install <a title="Download SQL Server 2008 R2" href="http://www.microsoft.com/sqlserver/2008/en/us/R2Downloads.aspx" target="_blank">SQL Server 2008 R2</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.datainspirations.com/2010/04/13/ssrs-page-number/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

