<?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>Thought Stuff &#187; SQL Server Reporting Services</title> <atom:link href="http://thoughtstuff.co.uk/category/development/sql-server-reporting-services/feed/" rel="self" type="application/rss+xml" /><link>http://thoughtstuff.co.uk</link> <description>tom morgan &#124; software engineer &#124; norfolk, uk</description> <lastBuildDate>Fri, 03 Feb 2012 21:51:55 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Reporting Services: Achieving Text Flow with Columns</title><link>http://thoughtstuff.co.uk/2011/03/reporting-services-achieving-text-flow-with-columns/</link> <comments>http://thoughtstuff.co.uk/2011/03/reporting-services-achieving-text-flow-with-columns/#comments</comments> <pubDate>Fri, 04 Mar 2011 18:26:20 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[alternative solution]]></category> <category><![CDATA[caption]]></category> <category><![CDATA[column table]]></category> <category><![CDATA[Mod]]></category> <category><![CDATA[number]]></category> <category><![CDATA[reporting services]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[Table]]></category> <category><![CDATA[text flow]]></category> <category><![CDATA[three tables]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=358</guid> <description><![CDATA[In a previous post I described how to create a Table of Contents for various sections of your report, to make it easier to navigate. One of the issues with the Index I created was that it was quite long. If your report has a lot of bookmarks, then your Table of Contents page is [...]]]></description> <content:encoded><![CDATA[<p>In <a
title="Reporting Services: Creating a Index / Table of Contents with Hyperlink Shortcuts" href="http://thoughtstuff.co.uk/2011/03/reporting-services-creating-a-index-table-of-contents-with-hyperlink-shortcuts/">a previous post</a> I described how to create a Table of Contents for various sections of your report, to make it easier to navigate.</p><p>One of the issues with the Index I created was that it was quite long. If your report has a lot of bookmarks, then your Table of Contents page is going to be pretty big. Well, it&#8217;s long. And thin.</p><p>What we really need to do is spread it out across the page a bit, so it can use some of the space over to the right hand side. Ideally, we want the table to support some form of Column Flow, so that the data in the rows seamlessly flowed into multiple columns, like a newspaper article.</p><p>Unfortunately, Reporting Services doesn&#8217;t do this out of the box. However, there&#8217;s a neat little trick which you can use to make it happen.</p><p>Just imagine for a moment the multi-column Table you&#8217;d like to see. It would have three separate columns side by side. And the headings of all your different Bookmarks would flow seamlessly in order, from left to right.</p><p>And that&#8217;s it. That&#8217;s how you can make it happen. Create three Tables, side by side, and fix the data each one has so that it looks right.</p><p>Keeping with my ideal of having the titles flow Left to Right, Top to Bottom for a moment (see at the end for an alternative solution), I&#8217;m going to continue using the data and tables from my previous post. Copy and Paste the original TOC twice, and lay them out next to each other:</p><div
id="attachment_359" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/TOCDuplicated.png"><img
class="size-medium wp-image-359" title="TOCDuplicated" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/TOCDuplicated-300x132.png" alt="" width="300" height="132" /></a><p
class="wp-caption-text">Duplicating the TOC</p></div><p>If you Preview the report now you&#8217;ll see that we now have three identical Tables.</p><p>Our data is already sorted alphabetically by Title. What we want is for the first table to display the first, fourth, seventh row, the second table to display the second, fifth, eighth row, and the third table to display the third, sixth, ninth row.</p><p>We can do this quite easily using the Mod, or <a
rel="nofollow" target="_blank" href="http://en.wikipedia.org/wiki/Modular_arithmetic">Modular</a> method. By applying a filter to the row based on the Mod of the row number with respect to 3, we can limit results to the first, second and third tables with a Mod value of 1, 2 or 0 respectively.</p><p>First, alter the result SQL to include the row number (notice how we can&#8217;t cheat and use DISTINCT anymore!):</p><pre class="brush: sql">
SELECT title,
ROW_NUMBER() OVER (ORDER BY title) AS row_num
FROM humanresources.employee
GROUP BY title
ORDER BY title
</pre><p>This gives us the row numbers to work with. Now, bring up the properties of the left-most table by right-clicking and selecting Properties. Under the Filter tab, add a new filter. The expression should take the form <em>=Fields!row_num.Value Mod 3</em> and the rest of the values should look like this:</p><div
id="attachment_360" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/NewFilter.png"><img
class="size-medium wp-image-360" title="NewFilter" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/NewFilter-300x163.png" alt="" width="300" height="163" /></a><p
class="wp-caption-text">Add New Filter</p></div><p>Now, repeat the process for the second table, changing the filter value to 2, and for the third table, changing the filter value to 0 (a Mod, or remainder, of zero will be every third row)</p><p>The final outcome is shown below: a nicely formatting set of three columns that looks like it flows:</p><div
id="attachment_361" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/FinalMultiCol.png"><img
class="size-medium wp-image-361" title="FinalMultiCol" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/FinalMultiCol-300x166.png" alt="" width="300" height="166" /></a><p
class="wp-caption-text">Final Output Showing Three Columns</p></div><h1>Alternative Layout Configuration</h1><p>Rather than the Left to Right, Top to Bottom approach described above, you may prefer to see a Top to Bottom, Left to Right flow where the items flow to the bottom of the first column before restarting at the top of the second. This can be done in a very similar way, but instead of using Row Number, we can use a SQL Server Function, NTILE to divide the result set into three:</p><pre class="brush: sql">
SELECT title,
NTILE(3) OVER (ORDER BY title) AS row_split
FROM humanresources.employee
GROUP by title
ORDER BY title
</pre><p>Because we passed &#8220;3&#8243; to the NTILE() function it splits the results equally into three. You can then use Mod as described above to divide the results amoung the three tables.</p><p>Note: this would work perfectly well with 2, 4 or 40 tables. I only pick three as it lays out nicely across the viewable area of the screen &#8211; there&#8217;s no other reason it can&#8217;t be any other number.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2011/03/reporting-services-achieving-text-flow-with-columns/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Reporting Services: Creating a Index / Table of Contents with Hyperlink Shortcuts</title><link>http://thoughtstuff.co.uk/2011/03/reporting-services-creating-a-index-table-of-contents-with-hyperlink-shortcuts/</link> <comments>http://thoughtstuff.co.uk/2011/03/reporting-services-creating-a-index-table-of-contents-with-hyperlink-shortcuts/#comments</comments> <pubDate>Thu, 03 Mar 2011 18:00:16 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[caption]]></category> <category><![CDATA[data]]></category> <category><![CDATA[dataset]]></category> <category><![CDATA[index table]]></category> <category><![CDATA[job titles]]></category> <category><![CDATA[random data]]></category> <category><![CDATA[Reporting]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[table icon]]></category> <category><![CDATA[width]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=315</guid> <description><![CDATA[If your report is very large and the data is grouped into different sections, you might want to think about making it easier for your users to navigate around. You can do this by providing bookmarks in your report, and a table of contents, or index, at the top which they can use to jump [...]]]></description> <content:encoded><![CDATA[<p>If your report is very large and the data is grouped into different sections, you might want to think about making it easier for your users to navigate around. You can do this by providing bookmarks in your report, and a table of contents, or index, at the top which they can use to jump to specific sections of the report.<span
id="more-315"></span></p><h1>Setting Up</h1><p>I&#8217;m going to use the Adventure Works database to get some names and departments. I&#8217;m using the following SQL to pull out some random data about people and the job titles they have:</p><p><code><pre class="brush: sql">&lt;/code&gt;&lt;code&gt;
select HumanResources.Employee.Title,Person.Contact.FirstName,
Person.Contact.LastName from
Person.Contact inner join
HumanResources.Employee
on Person.Contact.ContactID = HumanResources.Employee.ContactID
order by HumanResources.Employee.Title&lt;code&gt;
</pre><p></code></p><p>Here&#8217;s a sample of the data:</p><div
id="attachment_316" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSample.png"><img
class="size-medium wp-image-316" title="DataSample" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSample-300x267.png" alt="" width="300" height="267" /></a><p
class="wp-caption-text">Sample Data</p></div><p>In Reporting Services 2008, create a new report, but don&#8217;t use the wizard, instead choose to &#8220;Add an item&#8221; and select &#8220;Report&#8221;. Add whatever Data Sources you need to connect to your database and then add a dataset. For the purposes of this post, I&#8217;ll be adding the SQL text directly into the report: you should consider using a stored procedure for production reports, as it keep everything neater and allows more reuse.</p><p
style="text-align: center;"><div
id="attachment_324" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSetProperties.png"><img
class="size-medium wp-image-324 " title="DataSetProperties" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSetProperties-300x235.png" alt="" width="300" height="235" /></a><p
class="wp-caption-text">Create Dataset</p></div><p>Now, from the toolbox, drag in a Table. If you only have one dataset, it will be automatically chosen as the dataset for the Table, otherwise set it in the Properties. Click the blue table icon which appears as you hover over each field to add each of the three fields in. Your table should look like this:</p><div
id="attachment_328" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/Table.png"><img
class="size-medium wp-image-328" title="Table" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/Table-300x80.png" alt="" width="300" height="80" /></a><p
class="wp-caption-text">Table with Fields</p></div><p>Before we do anything else, let&#8217;s check everything has worked up to now, by Previewing the data:</p><div
id="attachment_323" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSample1.png"><img
class="size-medium wp-image-323" title="DataSample" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/DataSample1-300x267.png" alt="" width="300" height="267" /></a><p
class="wp-caption-text">Data Sample</p></div><h1>Group the Data</h1><p>For the purposes of this exercise, I&#8217;m going to group by title &#8211; because I want to be able to jump directly to specific titles . Right click the Title field to bring up the context menu. Choose to add a <strong>parent row group</strong>. (this is different to a column group &#8211; which you could also do, but will have different results. I&#8217;ve highlighted the correct Parent Group in the screenshot below:</p><div
id="attachment_320" class="wp-caption aligncenter" style="width: 224px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddRowGroup.png"><img
class="size-medium wp-image-320" title="AddRowGroup" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddRowGroup-214x300.png" alt="" width="214" height="300" /></a><p
class="wp-caption-text">Add a Row Group</p></div><p>From the dialog box, select the title as the row to group by, and specify that you want a group header:</p><div
id="attachment_319" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddNewGroupDialog.png"><img
class="size-medium wp-image-319" title="AddNewGroupDialog" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddNewGroupDialog-300x133.png" alt="" width="300" height="133" /></a><p
class="wp-caption-text">Add New Group</p></div><p>This will add a new column to hold the Title, and group the details by the Title. The table should look like this:</p><div
id="attachment_321" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AfterGroup.png"><img
class="size-medium wp-image-321" title="AfterGroup" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AfterGroup-300x91.png" alt="" width="300" height="91" /></a><p
class="wp-caption-text">After Adding a Row Group</p></div><p
style="text-align: left;">This need some tidying up &#8211; we have Title twice now. We no longer need our original Title (if you Preview now you&#8217;ll see that it will be repeated for every row which is pretty pointless), so we can delete it. I&#8217;m also going to rename the &#8220;Group1&#8243; title back to Title:</p><p><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AfterTidyUp.png"><img
class="aligncenter size-medium wp-image-322" title="AfterTidyUp" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AfterTidyUp-300x91.png" alt="" width="300" height="91" /></a>Now that I&#8217;ve done this, let&#8217;s Preview the data and see how it looks:</p><div
id="attachment_327" class="wp-caption aligncenter" style="width: 228px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/SampleDataGrouped.png"><img
class="size-medium wp-image-327" title="SampleDataGrouped" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/SampleDataGrouped-218x300.png" alt="" width="218" height="300" /></a><p
class="wp-caption-text">Sample Data Grouped</p></div><h1>Create a TOC</h1><p>So now I have my data looking how I want it, what about a Table of Contents. I&#8217;m going to create another Dataset, this time with just the Title in it, following the same process. To select all titles, I&#8217;m using the following SQL:</p><pre class="brush: sql">
SELECT DISTINCT title
FROM humanresources.employee
ORDER BY title
</pre><p>After adding another Table, this time having to choose the Dataset in the Properties, my Design window looks like this:</p><div
id="attachment_329" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/WithTOC.png"><img
class="size-medium wp-image-329" title="WithTOC" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/WithTOC-300x124.png" alt="" width="300" height="124" /></a><p
class="wp-caption-text">Design Window with TOC Table</p></div><h1>Create Anchors</h1><p>This is all very well, but now we need to do the clever bit: we need to create links in the top table that link to results in the bottom table.</p><p>SQL Reporting Services supports the concept of bookmarks. Similar to HTML anchor tags, you can specify parts of the report to be a bookmark, and then link to them from other parts.</p><p>First, let&#8217;s add some bookmarks to our data. We&#8217;ll add the bookmark to the Title text box, so that when we link to it, we can jump straight to that Title and see the people who have that title.</p><p>Click the Title box to view the Properties in the Properties window. (if you can&#8217;t see the Properties window press Alt+Enter.) Scroll down until you see the Bookmark entry. One of the most powerful feautures of Reporting Services is that nearly all the properties can be represented with an expression. You can change font, background colour, size, visibility &#8211; all based on expressions, and therefore data.</p><p>Choose the [Title] field from the drop down box:</p><div
id="attachment_318" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddBookmark.png"><img
class="size-medium wp-image-318" title="AddBookmark" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/AddBookmark-300x203.png" alt="" width="300" height="203" /></a><p
class="wp-caption-text">Add Bookmark</p></div><p>This means that each title that&#8217;s shown will also have a bookmark, with the name of the bookmark being the title. Unique, easily refrerenced bookmarks!</p><p>[as an aside, although Title works in this contrived demo, in the real world you'd want to use some sort of ID to group by, and therefore bookmark by.]</p><h1>Create Links</h1><p>Finally, we need to alter our top table to link to these bookmarks and make it a true Table of Contents.</p><p>Right click the title field in the top table, but this time choose Text Box Properties. This brings up the Properties dialog box. Under the Action section, select &#8216;Go to bookmark&#8217;. Again, in the drop down you can choose any of the fields from the table. In this case, we only have one &#8211; the [title] field.</p><div
id="attachment_326" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/LinkProperties.png"><img
class="size-medium wp-image-326" title="LinkProperties" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/LinkProperties-300x267.png" alt="" width="300" height="267" /></a><p
class="wp-caption-text">TextBox Properties</p></div><p>This will add the bookmark, but it won&#8217;t alter the formatting to make it obvious. I prefer to alter the text to be blue and underlined as most people understand this to be a clickable hyperlink.</p><p>Now, if we Preview we get a true Table of Contents, with clickable links:</p><div
id="attachment_325" class="wp-caption aligncenter" style="width: 310px"><a
href="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/Final1.png"><img
class="size-medium wp-image-325" title="Final1" src="http://thoughtstuff.co.uk/wp-content/uploads/2011/03/Final1-300x240.png" alt="" width="300" height="240" /></a><p
class="wp-caption-text">Final Design</p></div><p>Clicking any of the title links will jump straight to the relavent bookmark in the second table, acting just like a Index or Table of Contents.</p><p>You can tidy this up to make it more presentable. If you examine the properties of the TOC Table you can see that you can choose to force a page break after it &#8211; which can be handy in seperating the Index from the rest of the report.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2011/03/reporting-services-creating-a-index-table-of-contents-with-hyperlink-shortcuts/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>SQL Server Reporting Services: recently executed/modified reports</title><link>http://thoughtstuff.co.uk/2011/01/sql-server-reporting-services-recently-executed-modified-reports/</link> <comments>http://thoughtstuff.co.uk/2011/01/sql-server-reporting-services-recently-executed-modified-reports/#comments</comments> <pubDate>Thu, 06 Jan 2011 18:00:34 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[information]]></category> <category><![CDATA[INNER]]></category> <category><![CDATA[Report]]></category> <category><![CDATA[report server]]></category> <category><![CDATA[speed]]></category> <category><![CDATA[speed issues]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[sql server reporting services]]></category> <category><![CDATA[stack overflow]]></category> <category><![CDATA[t touch]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=264</guid> <description><![CDATA[Some quick SQL statements to easily find out what your most recently accessed reports, and your recently modified reports are, on your SQL Server Reporting Services instance.]]></description> <content:encoded><![CDATA[<p>Some quick SQL statements to easily find out what your most recently accessed reports, and your recently modified reports are, on your SQL Server Reporting Services instance.<span
id="more-264"></span>These can be useful if you need to tidy up your Report Server, and want to know which reports haven&#8217;t been used for a long time. Alternatively, if you&#8217;re experience speed issues, this might be a good place to start to see if the speed issues coincide with execution of a particular report.</p><p>Lots of useful information is stored in the Report Server tables &#8211; a list of all executions (report views) together with parameters, users, timing information, row counts etc. Just don&#8217;t touch anything &#8211; looking only! Check out the views as well.</p><p>Reports ordered by last executed:</p><pre class="brush: sql">
SELECT A.ItemPath,A.TimeStart,A.UserName
FROM ExecutionLog3 A
INNER JOIN
(Select ItemPath, MAX(TimeStart) as [LastExecuted]
FROM ExecutionLog3 GROUP BY ItemPath) as B
ON A.ItemPath = B.ItemPath AND A.TimeStart = B.LastExecuted
ORDER BY TimeStart desc
</pre><p>Reports ordered by last modified (with modifying user):</p><pre class="brush: sql">
SELECT Name, Path, Description, ModifiedDate, Users.UserName AS [ModifiedBy]
FROM [Catalog]
INNER JOIN Users ON Catalog.ModifiedByID = Users.UserID
WHERE type = 2
ORDER BY ModifiedDate DESC
</pre><p><em>Type=2 should include just reports. If you leave it out you can see Data Sources, folders, everything.</em></p><p>You should point these statements at your Report Server database for best effect. I am indebted to <a
rel="nofollow" target="_blank" href="http://stackoverflow.com/questions/4246001/t-sql-extra-column-in-group-by-how-to-include-in-results-but-exclude-from-group">this Stack Overflow post</a> for reminding me how to include the username on the recently executed report.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2011/01/sql-server-reporting-services-recently-executed-modified-reports/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SQL Server 2008 R2 System View Map</title><link>http://thoughtstuff.co.uk/2010/12/sql-server-2008-r2-system-view-map/</link> <comments>http://thoughtstuff.co.uk/2010/12/sql-server-2008-r2-system-view-map/#comments</comments> <pubDate>Fri, 10 Dec 2010 08:00:21 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[endpoints]]></category> <category><![CDATA[meta data]]></category> <category><![CDATA[PDF]]></category> <category><![CDATA[r2 system]]></category> <category><![CDATA[spatial indexes]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[View]]></category> <category><![CDATA[xps]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=245</guid> <description><![CDATA[Microsoft have a brilliant poster showing all the different system views which are available in SQL Server 2008 R2. The views are split into different sections (Endpoints, Spatial, Indexes etc) and all the relationships between the tables are shown. It&#8217;s really useful if you need some meta-data or just want to see what&#8217;s going on. [...]]]></description> <content:encoded><![CDATA[<p>Microsoft have a brilliant poster showing all the different system views which are available in SQL Server 2008 R2. The views are split into different sections (Endpoints, Spatial, Indexes etc) and all the relationships between the tables are shown. It&#8217;s really useful if you need some meta-data or just want to see what&#8217;s going on. It&#8217;s available in either PDF or XPS format, and can be downloaded directly from Microsoft here: <a
rel="nofollow" target="_blank" href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=65b81dce-db80-43f3-90e8-0753c751eaa7&amp;displaylang=en" target="_blank">SQL Server 2008 R2 System View Map</a></p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/12/sql-server-2008-r2-system-view-map/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SQL Server: converting rows to lists with &amp; without Coalesce</title><link>http://thoughtstuff.co.uk/2010/09/sql-server-converting-rows-to-lists-with-without-coalesce/</link> <comments>http://thoughtstuff.co.uk/2010/09/sql-server-converting-rows-to-lists-with-without-coalesce/#comments</comments> <pubDate>Tue, 28 Sep 2010 19:00:14 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[comma seperated]]></category> <category><![CDATA[data layout]]></category> <category><![CDATA[emotional security]]></category> <category><![CDATA[language text]]></category> <category><![CDATA[life without fear]]></category> <category><![CDATA[sourcecode]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[Statement]]></category> <category><![CDATA[type]]></category> <category><![CDATA[WHERE]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=198</guid> <description><![CDATA[Today I had a data layout issue to solve for a Reporting Services report I was writing. The report had to aggregate data from another table, but lay out the values into one row-space, comma seperated. These sorts of problems frequently crop up in less simple reports. I&#8217;m going to use the MSDN pubs database [...]]]></description> <content:encoded><![CDATA[<p>Today I had a data layout issue to solve for a Reporting Services report I was writing.</p><p>The report had to aggregate data from another table, but lay out the values into one row-space, comma seperated. These sorts of problems frequently crop up in less simple reports.</p><p>I&#8217;m going to use the MSDN pubs database as an example. If you don&#8217;t have it, you can install it from the <a
rel="nofollow" target="_blank" href="http://www.microsoft.com/downloads/en/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034&amp;displaylang=en">MSDN site</a>.</p><p>Consider this query:</p><pre class="brush: sql">
SELECT title FROM titles WHERE type = &#039;psychology&#039;
</pre><p>This will return 5 rows:</p><pre class="brush: text">
Computer Phobic AND Non-Phobic Individuals: Behavior Variations
Is Anger the Enemy?
Life Without Fear
Prolonged Data Deprivation: Four Case Studies
Emotional Security: A New Algorithm
</pre><p>You can use the <code>COALESCE</code> keyword to aggregate these values together into a comma-seperated string, but this requires the use of a SQL Parameter. Not a problem in itself, but you might be in a place where you can&#8217;t use parameters:</p><pre class="brush: sql">
DECLARE @Titles VARCHAR(250)
SELECT @Titles = COALESCE(@Titles,&#039;&#039;) + title + &#039;,&#039; FROM titles
WHERE type = &#039;psychology&#039;
SELECT @Titles
</pre><p>If you&#8217;re using this in a SQL Statement, maybe as a subselect, then this won&#8217;t work, as you can&#8217;t use the parameters within the <code>SELECT</code>, without turning it into a Stored Procedure, which seems overkill when all you wanted was a <code>SELECT</code> statement. This approach, however, will work:</p><pre class="brush: sql">
SELECT STUFF(
(SELECT &#039;, &#039; + title  FROM titles
WHERE type = &#039;psychology&#039; FOR XML PATH(&#039;&#039;)
),1,2,&#039;&#039;)
</pre><p>Both of these examples will output:</p><pre class="brush: text">
Computer Phobic AND Non-Phobic Individuals: Behavior Variations, Is Anger the Enemy?, Life Without Fear, Prolonged Data Deprivation: Four Case Studies, Emotional Security: A New Algorithm
</pre><p>In the last example, the outer <code>SELECT</code> can be part of a larger statement.  In fact, you could do away with the <code>STUFF</code>, as it&#8217;s the <code>FOR XML PATH('')</code> that does the magic. The <code>STUFF</code> just gets rid of the first comma.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/09/sql-server-converting-rows-to-lists-with-without-coalesce/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SQL Server Tip: NULLIF</title><link>http://thoughtstuff.co.uk/2010/09/sql-server-tip-nullif/</link> <comments>http://thoughtstuff.co.uk/2010/09/sql-server-tip-nullif/#comments</comments> <pubDate>Tue, 28 Sep 2010 16:25:39 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[calculating percentages]]></category> <category><![CDATA[nullif]]></category> <category><![CDATA[result]]></category> <category><![CDATA[server function]]></category> <category><![CDATA[server tip]]></category> <category><![CDATA[shame]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[today]]></category> <category><![CDATA[zero error]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=193</guid> <description><![CDATA[To my shame, I&#8217;d never come across this in-built SQL Server function unless today. The NULLIF function allows you to specify a NULL if the result was going to be something else: SELECT NULLIF(3+1,4) will return NULL. Full details here on the MSDN site. This has fixed my own immediate problem: that of diving by [...]]]></description> <content:encoded><![CDATA[<p>To my shame, I&#8217;d never come across this in-built SQL Server function unless today. The <code>NULLIF</code> function allows you to specify a <code>NULL</code> if the result was going to be something else:</p><pre class="brush: sql">
SELECT NULLIF(3+1,4)
</pre><p>will return <code>NULL</code>. Full details <a
rel="nofollow" target="_blank" href="http://msdn.microsoft.com/en-us/library/ms177562.aspx">here on the MSDN site</a>.</p><p>This has fixed my own immediate problem: that of diving by zero stopping play. Because I&#8217;m calculating percentages of run rates &#8211; if the initial value is zero, trying to work out a percentage causes the calculation stoppping:</p><p><code>Msg 8134, Level 16, State 1, Line 1<br
/> Divide by zero error encountered.</code></p><p>Helpfully though, by surrounding the value with a <code>NULLIF</code> to return a <code>NULL</code>, the enitre division calculation will be evaluated as a <code>NULL</code>: an apporiate conclusion for this sort of outcome.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/09/sql-server-tip-nullif/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Reporting Services Job Monitor</title><link>http://thoughtstuff.co.uk/2010/09/reporting-services-job-monitor/</link> <comments>http://thoughtstuff.co.uk/2010/09/reporting-services-job-monitor/#comments</comments> <pubDate>Mon, 20 Sep 2010 21:24:55 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[application]]></category> <category><![CDATA[microsoft report]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[Report]]></category> <category><![CDATA[report server]]></category> <category><![CDATA[Reporting]]></category> <category><![CDATA[reporting services]]></category> <category><![CDATA[rs web]]></category> <category><![CDATA[server functionality]]></category> <category><![CDATA[SQL]]></category> <guid
isPermaLink="false">http://thoughtstuff.co.uk/?p=176</guid> <description><![CDATA[I&#8217;ve just posted the source code to an application I wrote 2½ years ago, whilst at the same time started using it again. The Reporting Services Job Monitor (RSJM) application was originally written to monitor long running reports in Microsoft Report Server. Long running reports are easy to make (especially if your SQL is good [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve just posted the source code to an application I wrote 2½ years ago, whilst at the same time started using it again.</p><p>The<a
rel="nofollow" target="_blank" href="http://rsjm.codeplex.com/"> Reporting Services Job Monitor (RSJM)</a> application was originally written to monitor long running reports in Microsoft Report Server. Long running reports are easy to make (especially if your SQL is good enough to compile but not quite good enough to understand the dangers), hard to find and can cripple a report server. If that report server is also your production SQL Server long running reports can be a serious problem.</p><p>The first step in addressing the problem is visibility, which is what RSJM was written to do. Using the RS web service it checks for jobs starting and stopping, writing out a &#8216;report log&#8217; to the application. The application was posted to <a
rel="nofollow" target="_blank" href="http://www.codeplex.com/">CodePlex</a> as an MSI.</p><p>Recently, someone contacted me, asking if it was possible to monitor multiple servers. It certainly is possible, but isn&#8217;t something which RSJM currently does. I don&#8217;t really have the time to do this right now, but I saw no reason why I shouldn&#8217;t post the source to CodePlex, so that if other people want to add functionality, they can do. If they do, and it works, I can update the main MSI source on the project, so that everyone can use it.</p><p>Funnily enough, about the same time, we started to experience what I call &#8220;SQL brownouts&#8221; &#8211; random timeouts indicative of a long-running query. Somebody suggested the ability to monitor which jobs were running, which reminded me of the tool. Luckily I&#8217;d uploaded it CodePlex as I would have struggled to find it otherwise!</p><p>So, if anyone else wants to monitor Reporting Services jobs, have a look at RSJM. And if anyone fancies a small project, try adding multiple server functionality &#8211; the source is all on the <a
rel="nofollow" target="_blank" href="http://rsjm.codeplex.com/">RSJM Homepage</a>.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/09/reporting-services-job-monitor/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Managing &#8216;exclude&#8217; options in Reporting Services</title><link>http://thoughtstuff.co.uk/2010/08/managing-exclude-options-in-reporting-services/</link> <comments>http://thoughtstuff.co.uk/2010/08/managing-exclude-options-in-reporting-services/#comments</comments> <pubDate>Wed, 25 Aug 2010 16:45:54 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[car]]></category> <category><![CDATA[car showroom]]></category> <category><![CDATA[case statement]]></category> <category><![CDATA[jolly roger]]></category> <category><![CDATA[neat trick]]></category> <category><![CDATA[new car sales]]></category> <category><![CDATA[set]]></category> <category><![CDATA[Showroom]]></category> <category><![CDATA[way]]></category> <category><![CDATA[WHERE]]></category> <guid
isPermaLink="false">http://thoughtstuffsolutions.co.uk/?p=148</guid> <description><![CDATA[Here&#8217;s a good way of making reports more useful by including extra options. Sometimes, you will want to provide the option to exclude or include a particular set of data. For instance, when showing car sales over the last quarter for Jolly Roger&#8217;s Car Showroom, you may want to include second-hand sales, or specifically exclude [...]]]></description> <content:encoded><![CDATA[<p>Here&#8217;s a good way of making reports more useful by including extra options.</p><p>Sometimes, you will want to provide the option to exclude or include a particular set of data. For instance, when showing car sales over the last quarter for Jolly Roger&#8217;s Car Showroom, you may want to include second-hand sales, or specifically exclude them, looking only new car sales. (Assuming our sales table has a column for &#8216;SecondHandSale&#8217;)</p><p>This is a bit different for showing ONLY second hand sales or ONLY new sales: you want to show either both or just one sort.</p><p>You can achieve this in SQL using a CASE statement in your WHERE clause:</p><p><code>WHERE IsSecondHandSale =<br
/> CASE WHEN @ExcludeSecondHandSales THEN 0<br
/> ELSE IsSecondHandSale END</code></p><p>What you&#8217;re saying is that if second hand sales are excluded than the value in the IsSecondHandSale should be zero, otherwise it should be the same as it&#8217;s value. This will always be true, and so will ensure that all rows are returned.</p><p>This neat trick makes extending reports easy, and means you&#8217;re not duplicating reports just to show slightly different data.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/08/managing-exclude-options-in-reporting-services/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Microsoft® SQL Server® 2008 R2 Feature Pack</title><link>http://thoughtstuff.co.uk/2010/06/microsoft%c2%ae-sql-server%c2%ae-2008-r2-feature-pack/</link> <comments>http://thoughtstuff.co.uk/2010/06/microsoft%c2%ae-sql-server%c2%ae-2008-r2-feature-pack/#comments</comments> <pubDate>Tue, 08 Jun 2010 15:54:26 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[bits and bobs]]></category> <category><![CDATA[feature pack]]></category> <category><![CDATA[microsoft sql server]]></category> <category><![CDATA[Pack]]></category> <category><![CDATA[pack contents]]></category> <category><![CDATA[Report]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[today]]></category> <category><![CDATA[use]]></category> <category><![CDATA[visulisations]]></category> <guid
isPermaLink="false">http://thoughtstuffsolutions.co.uk/?p=97</guid> <description><![CDATA[Available from today, a collection of useful bits and bobs for use with SQL Server 2008. Amoung the included features is a new version of Report Builder, which includes support for the new visulisations, such as sparklines and maps. You can download the feature pack contents together, or piece by piece from Microsoft&#8217;s download page.]]></description> <content:encoded><![CDATA[<p>Available from today, a collection of useful bits and bobs for use with SQL Server 2008.</p><p>Amoung the included features is a new version of Report Builder, which includes support for the new visulisations, such as sparklines and maps.</p><p>You can download the feature pack contents together, or piece by piece from <a
rel="nofollow" target="_blank" href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52&amp;utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+MicrosoftDownloadCenter+%28Microsoft+Download+Center%29#tm">Microsoft&#8217;s download page</a>.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/06/microsoft%c2%ae-sql-server%c2%ae-2008-r2-feature-pack/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Using multi-select drop-down boxes as parameters in reports</title><link>http://thoughtstuff.co.uk/2010/05/using-multi-select-drop-down-boxes-as-parameters-in-reports/</link> <comments>http://thoughtstuff.co.uk/2010/05/using-multi-select-drop-down-boxes-as-parameters-in-reports/#comments</comments> <pubDate>Tue, 18 May 2010 18:19:00 +0000</pubDate> <dc:creator>Tom</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category> <category><![CDATA[choice]]></category> <category><![CDATA[code]]></category> <category><![CDATA[combo box]]></category> <category><![CDATA[drop down boxes]]></category> <category><![CDATA[format choice]]></category> <category><![CDATA[multi choice]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[SQL]]></category> <category><![CDATA[sql option]]></category> <category><![CDATA[way]]></category> <guid
isPermaLink="false">http://thoughtstuffsolutions.co.uk/?p=38</guid> <description><![CDATA[One of the options for a parameter is for it to be multi-selection. This is very useful for some report scenarios, and transforms the normal combo-box into something much more like the Excel filter drop down (why isn't this a native .NET control yet!)
However, the format of the data returned by this drop-down can cause problems if you're trying to run SQL from it.]]></description> <content:encoded><![CDATA[<p>One of the options for a parameter is for it to be multi-selection. This is very useful for some report scenarios, and transforms the normal combo-box into something much more like the Excel filter drop down (why isn&#8217;t this a native .NET control yet!)</p><p>However, the format of the data returned by this drop-down can cause problems if you&#8217;re trying to run SQL from it. I recently had just this problem, and I&#8217;m still working around it.</p><p>It took me a while to realise that the data returned from the multi-select box is in the format:</p><p>&#8216;choice 1, choice 2, choice 3&#8242;</p><p>This isn&#8217;t much good for use in SQL &#8211; especially if you were hoping to pipe this variable straight into an IN command. There&#8217;s probably not an entry in your table called &#8216;choice 1, choice 2, choice 3&#8242;, which is what you&#8217;re asking for.</p><p>The problem is clearer if what you&#8217;re looking for is an integer, rather than a varchar &#8211; as otherwise you can get held up thinking that you just need to put enough quotes in; you can&#8217;t! SQL Server is interpreting your variable as a single entry in the IN list, however you dice it.</p><p>You have some options here. The most appealing, but actually the most dangerous, slowest, least preferable option is to opt for some sort of dynamic SQL option and build up the IN statement yourself. I&#8217;m sure this would work, but just the fact that the code won&#8217;t be optimised was enough to turn me off: this is a hefty report and I didn&#8217;t want it to be slower than it was already going to be. If the values are variables, you&#8217;re also going to have to find a way of decorating them with quotes.</p><p>If the total number of records you would be returning without the multi-choice filter is quite small, or if you were returning them anyway for something else, then you can cheat and avoid the problem by bringing everything back and then filtering on the report side. Within the matrix or chart, or whatever is housing your data, you can filter, using the &#8216;In&#8217; operator and your parameter name in this format: [@VariableName] (with the square brackets). Don&#8217;t do this though unless you&#8217;re sure the extra load on the server won&#8217;t be a problem.</p><p>There is another way, which I will be implementing soon. That is to use a table variable within your SQL stored procedure, break out the values in the variable, insert them into the table variable, and then use that instead of the IN command. I&#8217;ll update this post with code just as soon as I&#8217;ve done it.</p> ]]></content:encoded> <wfw:commentRss>http://thoughtstuff.co.uk/2010/05/using-multi-select-drop-down-boxes-as-parameters-in-reports/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
