U2U Blog

for developers and other creative minds

Building custom reports for SQL Server management

Recently I presented a session at the ITPROceed conference on ‘Administration intelligence’: using Business Intelligence solutions for analyzing log files, generate documentation, do disk quota estimations and other typical administration tasks. You can find the full presentation at SlideShare.

In this blog post, I want to focus on one of the techniques explained in this talk: creating Reporting Services reports to run in Management Studio.

SQL Server Management Studio reports

SQL Server Management Studio contains a bunch of predefined reports. In the Object Explorer, right click any database, select Reports –> Standard Reports and you get a listing of nearly 20 predefined reports:


If we select any of these reports, a new tab open in Management Studio in which the report renders. There are a few special things to notice about these reports:

  1. They can be exported in PDF, Word and Excel format, as well as being printed
  2. It can be a multi-page report. There is no explicit way to go to the next or previous page, but if you scroll past the end of the current page, you go to the next page.
  3. The report is context sensitive: if you open the same report by clicking on a different database, it shows information for that specific database.

Before we dive into building our own reports, I just wanted to point out that we have these predefined reports not only at the level of databases, but also at the server instance level, as well as on the Data Collection node (Management), the Integration Services Catalogs (from 2012 on) and the SQL Server Agent node. Just go ahead and try these predefined reports: They provide very useful information without the effort of building reports yourself… plus they might inspire you in building your own reports.

From report consumer to report producer

These predefined reports can make our life easier, but sometimes you want a report different from these predefined reports.Building a custom report is easy.

Step 1: Retrieving the data

The first (and often most difficult) step in creating any report is in retrieving the right data. Luckily SQL Server provides tons of information via the many management views. Just start typing SELECT * FROM sys. and the completion tool will show you the huge list of possible completions. If you want to read more on these before you continue, checkout the web, e.g. mssqltips.com has some interesting reading material for you.

In this example we want to report on log file sizes: what are the biggest log files I have on any server, and home many room for growth (or shrinking) do we still have in there.

A query with which we can get started is this one:

FROM sys.dm_os_performance_counters
WHERE counter_name IN (
'Log File(s) Size (KB)'
,'Log File(s) Used Size (KB)'
AND instance_name <> '_Total'
This returns a table such as this:
But in reporting it is important to present the data as easy digestible as possible. It is easier to build reports if different measures (in our case log size and log used size) are in different columns versus all in one single column (as they are right now). The PIVOT statement in T-SQL might help us out on that. Also, simple resorting and renaming might improve the readability of the result. So after a bit of a rewrite we end up with this query:
SELECT [Database Name]
,[Log File(s) Used Size (KB)] AS LogUsedSize
,[Log File(s) Size (KB)] AS LogTotalSize
SELECT RTRIM(instance_name) AS [Database Name]
,cntr_value AS [Size in Kb]
,RTRIM(counter_name) AS [Counter Name]
FROM sys.dm_os_performance_counters
WHERE counter_name IN (
'Log File(s) Size (KB)'
,'Log File(s) Used Size (KB)'
AND instance_name <> '_Total'
) AS src
PIVOT(SUM([Size in Kb]) FOR [Counter Name] IN (
[Log File(s) Size (KB)]
,[Log File(s) Used Size (KB)]
)) AS pvt
ORDER BY [Log File(s) Size (KB)] DESC
Just copy the query in the clipboard, we will need it for the next step:

Step 2: Building the actual report

To build a report which we can run in Management Studio, we need to have SQL Server Data Tools (SSDT) installed (the tools formerly known as Business Intelligence Development Studio, BIDS, so you can use BIDS as well if you’re not yet on 2012). This is part of the regular SQL Server setup, so you can find it on your SQL Server 2012 or later installation media. But you can also just go and download it from the Microsoft Download Center.
After downloading, installing and starting this tool (which is just a Visual Studio template), we instruct it to create a new project. In the list of installed templates, you should find back the Business Intelligence group, select the Reporting Services group within, and on the right, click the Report Server Project Wizard and provide a useful project name:
Once you click OK, the wizard will start. Click Next to get past the start screen.
On the next screen the wizard asks which type of database connection we want to have, and to which server and database we want to connect. This is the tricky part, because we actually want to connect to whatever server and database we click upon in Management Studio object explorer. But now, we first need to develop this report in SSDT. Luckily, there is an easy way out: If we use the Microsoft SQL Server data source type, whatever server and database we select will be replaced with the ‘current’ server and database whenever we run this from Management Studio. So lets just connect to a server (I’m using localhost over here, but any server to which you can connect from SSDT will do):
Notice that if you want your report to not query the current database but a fixed database (e.g. always master or msdb), you should use three part names in your query (e.g. SELECT * FROM msdb.dbo.suspect_pages).
Next screen asks for the query to retrieve the data for this report. Paste the query we’ve written earlier in this blog into this window. The next screen asks for a report type, just confirm the tabular report. Then we have a screen that asks for the report design. Just drag all three fields into the Details window and click Finish. Then we hit the last wizard screen where we give this report a meaningful name: Log Size. Click Finish.

Step 3: fine-tuning the report

After we finish the wizard we end up in the editor. Click the preview tab to get an impression of what the report will look once deployed:
This report only looks slightly better than the table we got in Management Studio earlier on. We need to make a couple of improvements.
Switch back to the Design tab to widen the database name column (just drag the column header to the right).
Finally we want to have a graphical indication on the size of these log files. To achieve this, right-click the rightmost column header in our report and add a column to the right:
Next, from the Toolbox window, drag the Data Bar component into the bottom cell of this newly created column. In the pop-up window, just confirm the default data bar type. Finally, click the blue bar that appears in this cell. On the right another pop-up window appears. Click the green plus next to Values and click LogTotalSize:
Now preview the report again:

Step 4: Run in Management Studio

Now that we have a report which is easy to read, let’s make sure we can easily open up this report in Management Studio. In SSDT, in the File menu select Save Log File.rdl As... In the save dialog, navigate to My Documents > SQL Server Management Studio > Custom Reports and save it over there. Notice that this is not required, Management Studio can open reports from any file location; It’s just the default location for these files.
Finally, we can now open up Management Studio, right click any object in the object explorer, select Reports > Custom Reports, and select the file we just saved there.
If you can connect to multiple instances of SQL Server, try out this report on all of them, and you will see how the report takes the server context into account.
Right click to print and export the report… you can have all the options we had on the predefined reports.
This is not the end of it, it’s just the start. There is a lot more to learn about building Reporting Services reports, as well as about all the useful information we can extract from SQL Server. So, give it a try!


If you just want to download the .rdl file we created in this post, you can find it at http://1drv.ms/1yQjzMD

Comments (61) -

  • tents

    6/10/2015 9:06:51 AM |

    Whats up. Very nice site!! Man.. Excellent.. Amazing.. I all bookmark your blog and take the feeds alsoI am glad to find a lot of useful information right here in the article. Thanks for sharing..

  • www.boletineselectricos.es

    6/10/2015 1:35:55 PM |

    Some times its a pain in the ass to read what  blog owners  wrote but this  site is  really  user  genial !.

  • breastcancer

    6/11/2015 12:49:42 PM |

    Im obliged for the article.Thanks Again. Fantastic.

  • crazy paving contractors melbourne

    6/14/2015 10:49:01 AM |

    Im grateful for the post.Really looking forward to read more. Cool.

  • jasa sewa mobil Manado

    6/14/2015 5:19:23 PM |

    Looking forward to reading more. Great article.Really looking forward to read more. Keep writing.

  • miracolo per acufeni funziona

    6/15/2015 2:47:27 PM |

    I really liked your blog article.Really looking forward to read more. Great.

  • libera dalla cellulite opinioni

    6/16/2015 1:14:46 AM |

    I loved your blog post.Really looking forward to read more. Cool.

  • electricistas madrid baratos

    6/16/2015 7:29:46 AM |

    I really liked your article.Much thanks again. Cool.

  • Rand Spear

    6/16/2015 8:59:59 AM |

    valuable know-how regarding unpredicted feelings.

  • cerrajeros valencia capital

    6/17/2015 11:41:23 AM |

    Whoa! This blog looks just like my old one! It as on a entirely different topic but it has pretty much the same layout and design. Outstanding choice of colors!


    6/18/2015 4:08:02 PM |

    This is really interesting, You are a very skilled blogger. I ave joined your feed and look forward to seeking more of your fantastic post. Also, I have shared your website in my social networks!

  • backlinks google

    6/18/2015 8:38:58 PM |

    Not just top quality, yet likewise valuable info. And that is unusual to come by these days! I have to say that I am truly impressed and also will certainly come back once more if you keep up the high quality and worth of the content at this degree, or also acquire it on the following degree.

  • link building in 2015

    6/19/2015 1:36:51 AM |

    Simply outstanding! I know you have actually placed a great deal of effort right into this and I wanted to tell you exactly how thankful I am! Hope you put out even much more incredible stuff in the close to future and also I will certainly come back and read it!

  • private label formula development

    6/22/2015 1:29:35 PM |

    Ideas Including A business idea to aid head inside path of success should be to offer incentives in your current clients or incentives to lure a new in

  • eCommerce business

    6/23/2015 3:38:43 AM |

    I think this is a real great blog article. Want more.

  • nude xxx

    6/24/2015 5:09:37 AM |

    Wow, great blog post.Much thanks again. Cool.

  • Boxing June 2015

    6/24/2015 1:26:55 PM |

    Very neat blog post. Keep writing.

  • aids

    6/25/2015 5:08:19 PM |

    Great, im into all kinds of nasty porno

  • link building

    6/26/2015 2:33:06 AM |

    Wow! Just outstanding! Thanks a lot for the details discussed! I recognize you have placed a lot of initiative right into this as well as I would like to inform you how happy I am! There need to be more blogs similar to this on the web! I will certainly bookmark as well as subscribe to your impressive site! Hope you put out much more amazing stuff in the soon as well as I will certainly come back and also review it! Keep up the great work!

  • link building campaign

    6/26/2015 4:25:57 AM |

    Not simply reputable, yet additionally valuable details. And also that is uncommon to come by these days! I have to claim that I am actually amazed and also will surely come back again if you maintain up the reputable and worth of the material at this degree, or even get it on the following level.

  • De gule sider telefoninformation

    6/26/2015 4:45:46 PM |

    I think this is a real great blog. Awesome.

  • vaporisateurs

    6/29/2015 3:25:05 AM |

    I think this is a real great blog article.Really looking forward to read more. Will read on...

  • annuaire rose

    6/29/2015 6:47:47 AM |

    A big thank you for your blog article.Thanks Again. Great.

  • June Post

    6/29/2015 9:01:53 AM |

    Im obliged for the blog. Keep writing.

  • home

    6/29/2015 2:34:40 PM |

    Muchos Gracias for your blog article.Really thank you! Much obliged.

  • My Camp

    6/30/2015 4:49:00 AM |

    I am so grateful for your article post.Thanks Again. Awesome.

  • solar modules

    7/1/2015 2:31:45 AM |

    Hey, thanks for the post.Really thank you!

  • seo link building

    7/6/2015 4:40:59 AM |

    Merely outstanding! I know you have put a lot of effort right into this as well as I wanted to tell you just how thankful I am! Hope you placed out even more remarkable things in the near future as well as I will certainly come back and also read it!

  • seo link building

    7/6/2015 10:20:40 AM |

    Merely awesome! I understand you have put a lot of effort into this as well as I wanted to inform you exactly how happy I am! Hope you placed out even more outstanding things in the close to future as well as I will certainly come back and also review it!

  • rachel roxxx

    7/21/2015 10:56:41 PM |

    I am so grateful for your article.Much thanks again. Want more.

  • eebest8 seo

    8/15/2015 7:24:55 AM |

    Really appreciate you sharing this blog post.Much thanks again.

  • sincoole technology

    8/28/2015 12:14:45 AM |

    we provide rugged smart terminal, include rugged tablet, rugged handheld terminal. 2D barcode rugged tablet, fingerprint rugged tablet, RFID rugged tablet, tough tablet, rugged mobile phone, tough phone. multifunction include RFID UHF 13.56MHz, Barcode reader, Finger printer, infrared ray and so on. we also use Gorrila, TFT screen on it. every function and size can customize. more information, you can contact me, email: gavin.fan@sincoole.com, website: www.sincoole.com, or www.sincoole.net, skype: sincoole

  • you can check here

    9/7/2015 9:06:29 PM |

    I simply want to say I'm very new to blogs and certainly liked this blog site. Very likely I’m want to bookmark your blog . You absolutely have great posts. Appreciate it for revealing your blog site.

  • 新竹餐廳

    9/9/2015 12:39:01 PM |

    <a href="http://www.mysimply.com.tw";>新竹餐廳</a>雅米餐廳還有包廂提供歡唱給一群朋友聚會邊唱邊喝邊吃非常盡興。

  • 竹北餐廳

    9/10/2015 12:26:09 PM |

    <a href="http://www.mysimply.com.tw";>新竹餐廳</a>有附沙拉、小菜及甜點,小菜有泡菜跟一個涼拌菜,味道都不錯唷一舉兩得。

  • 植牙

    9/21/2015 6:12:43 PM |

    <a href="http://www.sourcecode.com.tw";>植牙</a>的過程,我們採微創療窗C不隊M,以雷射瞬間氣化小圓孔,再進行植牙。整個療竣ㄥ刀、不流血、不腫脹、傷口癒合特快。

  • Tyson Ritzke

    9/24/2015 1:49:08 AM |

    This article is very super, just what i am looking for to go through on my downtime. Thanks Again

  • 植牙

    9/26/2015 6:38:12 PM |

    <a href="http://www.superbowl.com.tw";>植牙</a>手術除了一般缺齒患者,最需要植牙手術的族群就是老年人了。人年紀漸長、身體退化,不只是皮膚上的老化,連肌肉組織、骨骼甚至是牙齒都會退化。老 年人口腔退化最主要是由於更年期過後,口水變少演變成乾口症,口水少導致口腔抵抗力變低,也因此容易造成蛀牙或是牙周病。因為蛀牙或是牙周病造成的牙齒脫 落與損耗就需要人工植牙手術的幫助了。

  • 抽脂

    10/7/2015 4:02:29 PM |

    <a href="http://www.lshglass.com.tw";>抽脂</a>除了可以消除掉身體不需要的脂肪外,更可以廢物利用,將抽出來的脂肪移到身體其他部位,比如說隆乳或是補臉,一舉兩得。

  • astral projection

    10/11/2015 2:53:59 PM |

    This article is very supernatural, just what i am currently looking for to look over on my short break. Thanks

  • astral projection

    10/11/2015 5:58:48 PM |

    This article is very supranatural, just what i was looking for to read on my time out. Thank You

  • 近視雷射

    10/19/2015 2:29:45 AM |

    <a href="http://dddd.com.tw";>近視雷射</a>是利用雷射雕塑微透鏡角膜組織,接著雷射製作小於4mm的微創切口取出組織,手術即完成,藉此達到準確的視力矯正效果,微創傷口恢復快、風險大幅低,準確率高,安全性大大提升。

  • 抽脂

    10/24/2015 6:09:25 PM |

    <a href="http://www.lshglass.com.tw";>抽脂</a>除了可以消除掉身體不需要的脂肪外,更可以廢物利用,將抽出來的脂肪移到身體其他部位,比如說隆乳或是補臉,一舉兩得。

  • Escort ankara

    10/27/2015 6:34:30 PM |

    Vipbayanlar - Aldus PageMaker gibi Lorem Ipsum sürümleri içeren masaüstü yayıncılık yazılımları ile popüler olmuştur.

  • rB2Tsz0

    11/7/2015 2:47:45 PM |

    22856 900141I just added this weblog to my rss reader, superb stuff. I like your writing style. 317173