You are on page 1of 21

Beginning SQL Server 2005 Reporting Services Part 1

3/1/12 10:13 AM

Beginning SQL Server 2005 Reporting Services Part 1
24 August 2006 by Steve Joubert

Building and deploying basic reports


f ever there was job for "real" developers to shuffle to their juniors, it is building reports. It's not real development anyway; it's more like glorified formatting. Besides, the esoteric tools that you use to build reports try to provide an abstraction layer, which often prevents you from having any real control over the report. I've heard all these arguments before. If this sounds like a conversation you've had by the water cooler, then I invite you to take a closer look at SQL Server 2005 Reporting Services (SSRS). SSRS 2005 is the latest version of SQL Reporting Services, and ships with all versions of SQL Server 2005. SSRS allows you to quickly and easily create reports from multiple database sources. The finished reports can be presented directly from the reporting services website, or they can be displayed in your web- or Windows-based applications. Reports can be exported to multiple formats, including comma delimited text, XML, portable document format (pdf) and Microsoft Excel. This article is the first of four parts, which will provide in-depth coverage of SQL Server 2005 Reporting Services: Part 1 covers the basics of the SSRS. It demonstrates how to build quick, simple reports and will familiarize you with the basic Report Designer environment Part 2 will cover use of custom functions, aggregate functions, sub-reporting, the matrix control, drill-downs, and sorting. Part 3 will take an in-depth look at the charting control Part 4 digs into the actual Report Definition Language (RDL) and the new Report Builder tool.

Installing and configuring Reporting Services
After much debate, we decided that full installation and configuration details were outside the scope of an article focused on how to build basic reports using SSRS, especially as there are already several online resources that treat this area in detail. See, for example: and Well worth reviewing are the details in the latter on the need to install SSL on any machine hosting SSRS. ---Editor's installation notes--In order to test the reports in this article, I went through a single-machine installation on Windows XP (meaning that SQL Server 2005, Reporting Services, and much more, are all installed on my poor laptop). Since I didn't install SSRS when I installed SQL Server 2005 (I didn't have IIS installed at the time), I had to first install IIS 5.1, and then Reporting Services (from the SS2005 disks). I then jumped immediately into Reporting Services Configuration Manager tool (All Programs ¬ SQL Server 2005 ¬ Configuration tools). The left panel acts as a sort of checklist of items to configure:

Page 1 of 21

Beginning SQL Server 2005 Reporting Services Part 1

3/1/12 10:13 AM

All went well until the Database Setup. Because I had not installed SSRS at the same time that I installed SQL Server, the ReportServer and ReportServerTempDB were not created by default. These databases hold all the report definitions and reporting server configuration information. Connecting to SQL Server using Service Credentials, the databases appeared to be created, but I received an error suggesting that I didn't have permissions to perform the requested task, and a red cross remained next to the Database Setup icon. This had me stumped for a while – eventually I appeared to solve it by hopping to the Server Status section, stopping the Report Server, opening SSMS and deleting both the ReportServer and ReportServerTempDB databases, and then restarting the Report Server and trying again! Even though I swear this didn't work the first time I tried it, it seemed to do the trick the second time (while I was on the phone moaning to Steve that I couldn't get it to work!). However, I'm still not clear why I had the problem in the first place – or why it suddenly went away. This wasn't quite the end of my problems. Installing SSRS creates two new virtual directories under the default website on IIS. By default, they are named Reports and ReportServer. The ReportServer site hosts a web service for running and managing reports. The Reports site allows you upload reports from a browser and run reports over the web. When I tried to navigate to http://localhost/ReportServer I received the following error: "Failed to access IIS metabase". Fortunately, the information on the error page is quite useful (for a change) and this, coupled with a quick Google search, led me to grant access to the metabase to the ASPNET user account by executing the following from the directory housing the aspnet_regiis executable (WINDOWS\Microsoft.NET\Framework\v2.0.50727, in my case):

spnet_regiis -ga ASPNET

This did the trick, and I was up and running. I received some raised eyebrows here when I proposed to install SSRS. It made my long-suffering sys admin team particularly nervous. The 2000 version of SSRS seems to have a very bad reputation among the Red Gate team, both as a performance nightmare, and in one case for "completely annihilating" a developer's machine. However, the above slight quirks aside, the SSRS 2005 experience seems pretty smooth and I've had no real performance, or other, issues. So far. Page 2 of 21

The code file contains a sample Visual Studio project and a SQL Script for creating the ReportDemo database. or you can use the Report Wizard to give yourself a head start.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM -----End of Editor's note---Once you've completed the installation and configuration process. the first thing to do is download the code file for this article (see the Code Download link in the speech bubble to the right of the article title). Select the Report Wizard option and call the file "FirstReportWZ. Note: Use of the Shared data source option is actually a better option in most cases but. we will just create a new data source. Start a new Business Intelligence project in Visual Studio 2005. Click the Edit button to bring up the Connection Properties dialog: http://www. by restoring the provided ReportingDemo. Using the Report Wizard There are two ways to create SSRS Reports. For this first report. from the menu. You can build the report manually. Then. Click Next on the Welcome screen and this will bring you to the Select the Data Source screen: Select the New data source radio button and give the data source a name. If you are using SQL Server Authentication on your SQL Server you will also need to set up a login with permissions to the ReportDemo database (for the examples. select Project > Add New Item. Click Add.sql script or. alternatively.bak file. You will need this database if you want to follow the examples in this series of articles so go ahead and create the database using the ReportingDemoDatabaseScript. for the sake of this example.simple-talk. We're going to set up a shared data source later in this article.aspx?article=268 Page 3 of 21 .com/content/print. Select Microsoft SQL Server as the type.rdl". we are going to take advantage of the wizard. I set up a login called DemoUser as a DBO on my ReportDemo database).

This brings up the Design the Table screen: http://www. select a database. and enter the username and password. in this case ReportingDemo. choose that setting. If you are using SQL Server Authentication. but in this case simply enter "Select * From Customer" into the Query string text box and click Next. Next up is the Design the Query You can use the Query Builder by clicking the button at the top left.simple-talk. Finally. On the Select the Report Type simply select the type you prefer (tabular or matrix) and hit Next. The default is to log on using Windows Authentication. Make sure you test the connection before you click OK.aspx?article=268 Page 4 of 21 .Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Enter or select a server name.

Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Select State in the Available fields box and click the Group button. This will group the data in the result set by State. Select Next. choose a style for your report (I chose Ocean) and click Next. On the Choose the Table Layout page. This brings up the final screen.simple-talk. Completing the Wizard: http://www. select the Stepped option and check the Enable Drilldown checkbox. On the next Page 5 of 21 .

and gives you an opportunity to rename the report and to preview it. You should be shown the report in the standard Report Designer: http://www.simple-talk.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM It shows a summary of your report options.aspx?article=268 Page 6 of 21 . Click Finish to end the

it will run as soon as you click on the tab. Layout and Preview. You should be on the Layout tab. Since this report doesn't take any arguments. Click on the Preview tab to view the report.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM There are three tabs: Data.aspx?article=268 Page 7 of 21 .

you still have to set up a data source object for each of three environments. all of the reports on a reporting server. If you put the connection information into each report. let's say your company has Development. In this section.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Use the +/. does show you how to get a report up and running with zero code and zero property setting.aspx?article=268 Page 8 of 21 . such reports will not meet most development requirements. you will have to change it each time when you publish to Development. If you use a shared data source. but do not discount this option as a starting point for more complicated reports. http://www. and can be used by. but you can simply publish the report to each environment. Test and Production environments. and how to format your report. Manual report creation The previous section. stored procedures. set report properties and use report parameters. including how to create and use a shared data source object. Obviously. For example. as it will save you a lot time and headaches. while perhaps overly simplistic. Test and Production. you only have to set the connection information once. a data source that is common to.symbols next to the State abbreviations to expand and collapse the grouping of the report. While each report can contain its own connection information. and they will automatically use the connection information associated with that environment. This you are free to make any modifications to it. Once you've created a report with the Report Wizard.e. Creating a shared data source Before we start the report. we are going to create a more realistic report from scratch. it is good practice to use shared data sources. we are going to build a shared data source i.simple-talk.

At this point. Click the Edit button on the right. The Data tab is used to build data sources for your report. The Preview tab allows you to actually run the report from Visual Studio 2005. and the Report Designer will open at the Data tab.rdl". as before. At the top of the Data tab choose <New Dataset…> from the dropdown list: The Dataset dialog opens: http://www. without having to publish it to a report server first.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM From the menu select Project > Add New Item > Select Data Source. On the General tab. let's take a closer look at the Report Designer tool. Add a new report From the menu select Project > Add New Item. the footer and the data presentation of the report. A new report will be added to the project. Select Report and name it "FirstReportMan. The first thing we need to do is get data into our report. Leave the Type as Microsoft SQL Server.aspx?article=268 Page 9 of 21 . If your report takes Click OK on the Shared Data Source screen and the data source is done. At the top of the Report Designer window are three tabs: Data. The Layout tab is the physical report designer where you set up the header. call the data source "ReportsDB". and enter the connection information for Reporting Demo. the Preview tab will ask you to fill them out before it runs the report. Layout and Preview.simple-talk.

Select StoredProcedure as the command type. onto the Body section of the report. Now put the LastName in the second column.simple-talk. This executes the query and displays the results.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Name the dataset "ReportData". a detail row in the middle and a footer row at the bottom. By default. select FirstName and drag it to the first cell of the body row of the table. Click OK to close the dialog. Test the dataset by clicking on the big red exclamation point at the top of the report designer. You can add additional columns to the table by right-clicking on one of the columns and selecting one of the two Insert Column options. and select the ReportsDB data source from the dropdown. the table shows a header row at the top. Expand it. You should see the ReportData dataset. switch to the Layout tab. Note: spr_CustomerSelectAll is a very simple. Setting up the report display Next. This is where you actually build the report display.aspx?article=268 Page 10 of 21 . and enter "spr_CustomerSelectAll" in the query string box.sql script with the code download. parameter-less stored procedure that selects all of the columns from the Customer table. You can repeat these steps if you wish to add multiple datasets to your report. and the CustomerStatus in the third: http://www. Start by dragging a table from the Toolbox. This will display the First Name field in the first column. The source code is included in the ReportingDemoDatabaseScript. Click on the Datasets tab under Toolbox on the left-hand side of the Visual Studio

It calls it "First Name".com/content/print. when you drag the column FirstName into the body row of the table. SSRS make a guess as to what to call the row. You can click on the Preview tab to view the report. very plain. Let's add the DateOfBirth column to the table. You can expand and shrink the size of the columns by highlighting and dragging: http://www.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Note that.aspx?article=268 Page 11 of 21 . Adding formatting OK. so we have a basic. Let's add some formatting to make it look good.simple-talk. report.

com/content/print. Open the Properties window and set background color. click and drag over all the cells to select them. and so on. You will see a grey box surround the table.aspx?article=268 Page 12 of 21 . font. Right-click on the icon at the beginning of the body row and then click the Table Footer option to deselect it. http://www.simple-talk. To format all the cells in the header in the same way.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM If you wish to get rid of the footer row of the table and then click on any field in the table. The table header is next.

Drag a text box onto the header and click directly on it. Type "My First Report". A new band labeled Page Header appears on the report above the that if you wish to change the justification of the text or the size. Again.simple-talk. Put the Report Designer in Layout mode and select Report > Page Header from the menu. not in the Properties window. but the report can also have a header and footer. Add a report header The table already has a header. then you do so using the main menu at the top. Report headers and footers appear on every page of the report.aspx?article=268 Page 13 of 21 . http://www. not via the properties window.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Note. you can click on the Preview tab to view the report. however. but right on the control.

simple-talk. highlight the text box and use the option from the top menu. Formatting Each field can have formatting. The time information is superfluous. so let's format the date properly. select the Format tab. Let's deal with that ugly Date of Birth field. http://www.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM To adjust the text style and size of your heading. and choose Properties. Right-click on the cell that contains the date of birth.aspx?article=268 Page 14 of 21 .com/content/print. Next.

simple-talk.aspx?article=268 Page 15 of 21 . http://www. Select Date in the list on the left. then choose the sample date format you want on the right. use the standard When the dialog opens. Click OK to close the dialog.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Click on the second button (labeled "…") to the right of the Format code field.

Report. compared to other products.5 inches for content. you need to be on the Layout tab of the Report Designer. A standard sheet of paper is 8. Setting up the report print settings is not intuitive. http://www.aspx?article=268 Page 16 of 21 . and setting report parameters. setting report properties. When you click on this tab. In the report Layout tab you see your report with a ruler across the top. you have 6. To get Landscape reports. at 8. It will not automatically shift to Landscape. you have to make the proper report settings. The default setting in SSRS is to have a 1-inch margin all the way around the content area.5 x 11 inches. you need to change Page width to 11in and the Page height to 8. That ruler is set up in inches.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Click OK to close the Properties window and then click on the Preview tab to view the report.5 inches wide with a 1-inch margin on the left and another on the right. To switch to Landscape printing. activates. From the Report menu select Report Properties. So. adding embedded Switch to the Layout tab of the dialog box. This menu gives you options for turning on and off the report header and footer sections (as we have seen). Any more.5in. a new menu item.simple-talk.5 inches will spill over onto a second sheet of paper when printed. Navigate to the Layout tab of the Report Designer. Setting report properties To access the report properties. and the content beyond the 6.

you can also get up your report to display the data in multiple columns. Enter "Louisiana" and "LA" on the second line. The second is to set up parameters through the Report Parameters dialog Enter "CA" and click the View Report button. http://www. The query should return all the customers that live in California. The Dataset dialog box opens and allows you to edit the query for the dataset. is greater than the width of the printer. To edit the parameters. We will do both. In the Available values section enter "California" and "CA" on the first line. Instead of the report just running. if your report width. The first is to use parameters in the queries in your data sources. change the prompt to read "State". Change the Query string from "spr_CustomerSelectAll" to "spr_CustomerSelectByState".simple-talk. First. Select StateCD in the Parameters list box then. Again. and click the "…" button right next the Dataset dropdown box. and you can control the margins. Navigate to the Data tab. Note: spr_CustomerSelectByState accepts a parameter called StateCD that allows us to filter the data from the Customer table by State. By default. there should be a place for you to enter a value for the "StateCD" and run the report. or to add new ones. Query parameters First. Remember. Enter "CA" and click OK. Click OK and then run the query by clicking the red exclamation point (!) on the Data tab toolbar. You will be prompted to enter a parameter value for StateCD (the State code). You should see your report filtered by state. plus the right and left margins.aspx?article=268 Page 17 of 21 . you will get spill-over when you print out your report.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM On the same Layout tab. Using parameters There are two ways to add parameters to your reports. we are going to make the "State code" prompt a little more friendly. switch to the Layout tab of the Report Designer and open the Report Parameters dialog from the Report menu. all the margins are set at 1 inch.sql script with the code download. Switch to the Preview tab. the source code is included in the ReportingDemoDatabaseScript. we will set up parameters using a data source query. in the Parameters Properties box.

Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM This will make the prompt for "State value" into a dropdown. and use the values in those datasets as criteria for dropdowns. This text box will now display the value you pass to the Report Title parameter. You can also build additional datasets into your report. Its Data type should be String. http://www.simple-talk. Give the new parameter the name "ReportTitle". In the Edit Expression dialog select Parameters. Drag a new text box onto the report header area.aspx?article=268 Page 18 of 21 . Double-click on the ReportTitle Right-click on it and choose the Expression option. Click OK and close the dialog box. Set the Prompt to "Report Title". Report parameters Now let's add a parameter that is not used in a query. Click the Add button in the Report Parameters dialog from the Report menu.

Publishing your reports Up to now. The easiest way to do this is to have Visual Studio publish your Start by right-clicking on Project in the Project Explorer and choose Properties.Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Switch to the Preview tab and try it out. to make them useful.aspx?article=268 Page 19 of 21 . you have been running your reports in the Visual Studio 2005 environment but. http://www. you must publish them to a report server.

When set to "False". If the folder does not exist. so does the SQL that underpins them. you can also print or export the You can publish a set of data source objects to each server. However. with the reports in it. From the Build menu select Deploy Solution. but it will not overwrite existing ones. Wrap up That's everything you need. Use the TargetReportFolder property to set up a folder for your reports. Steve Joubert continues this introductory article in Beginning SQL Server 2005 Reporting Services Part 2. it will automatically copy over all your data source objects when you publish. The other key thing to pay attention to here is the OverwriteDataSources property. In this article. and never have to worry about what database your reports are hitting in each environment. http://www. This will publish the project to the selected folder on your report server. test and production servers. sorting and custom functions. pointed at the correct database. you should be able to find the folder you published to. Select a report to run. At the top of the page you can enter any values for report parameters. Easier Report Development. to build a very basic report. From the Home page. the Publisher will create it for you. Create reports quickly and accurately using SQL Prompt. You can also deploy individual reports by right-clicking on the file in the Solution explorer and selecting Deploy. you can access and run it on your server through the browser at http://<servername>/<reportservername>.aspx?article=268 Page 20 of 21 . Stay tuned. Red Gate's powerful code completion tool. This is important when dealing with development. When this property is set to "True".Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM Set TargetServerURL to the URL of your report server. If you enjoyed this article. In the next articles we'll get into adding some more advanced options such as drill-downs. make sure you see Ten Common SQL Server Reporting Services Challenges and Solutions and other Reporting Services articles in our Reporting Services section.simple-talk. as the complexity of your reports increases. From here. and then run the report. Once your report has been published. Steve Joubert offers a great introductory guide to creating reports using SSRS. it will copy any new data source objects.

Beginning SQL Server 2005 Reporting Services Part 1 3/1/12 10:13 AM © Simple-Talk.aspx?article=268 Page 21 of 21 .com/content/ http://www.