SSRS Tutorial
SSRS Tutorial
SSRS or SQL server Reporting Services which is also called Microsoft SQL reporting, is a component
of the Microsoft BI stack.
The Microsoft Business Intelligence Stack mainly consists of SQL Database Engine, SSRS, SSAS, SSIS
and other tools
SSRS is a set of readymade tools, which helps you to create, deploy and manage reports.
Microsoft SSRS or Business Intelligence SSRS, let’s you create very rich reports
(Tabular/Graphical/Interactive/free-form) from various datasources with rich data visualization
(Charts, Maps, sparklines).
SSRS allows are reports to be exported in various formats (Excel, PDF, word etc)
SSRS allows reports to be delivered via emails or dropped to a share location in an automated
fashion.
SSRS provides a host of security features, in order to control, who sees which reports etc.
Move forward with getting to know how to install sql server 2008 reporting services. Please note, most
of the steps are the same for installing sql server reporting services 2005.
Below are the steps to install SQL reporting services 2008 with express Database.
Step 1: Download the 64 bit or 32 bit version of SQL 2008 Express with advances services from here .
Step 14: Next, select Named Instance and give it any name (you can also choose Default instance)
Step 17: Click next, and select 'Install, but do not configure under Reporting Services configuration.
Step 18: Click Next
Your installation is almost complete. In order to start using SSRS, you need to perform a few more steps.
Step 23: Click Start --> All programs --> Microsoft SQL 2008 --> Configuration Tools --> Reporting Services
Configuration --> select your instance
Step 24 : Click web service URL on the left hand side and click the apply button.
Step 25: Click database on the left hand side, select change database --> create a new report server
database and complete the steps.
Step 26: Click report manager URL and click apply (Note down the URL displayed. It should be of the
form http://machinename/reports)
That's all. We are all set. install some sample databases and get started learning SSRS 2008
Lesson 3: Installing Sample databases (Adventure Works)
Next, install some sample databases for us to work with. One of the most commonly used databases is
the SQL adventure works database. SQL server adventureworks database download is available here.
Once you download the database, look at how to setup sql database.
Step 1: Install your downloaded database (sql server 2008 sample databases download), by choosing the
correct instance name.
Step 2: After installation, open SSMS --> your instance name, then check if the below databases are
visible.
Step 3: You can also install some sample reports from here
Lesson 4: Creating your first SSRS report.
Now that you are all set with installing SSRS 2008 and some SQL server adventure works database, Let
us proceed with creating our first SSRS report, deploying the same and viewing in the web browser. For
report development, we will use Microsoft Business Intelligence Development studio. Quite often
people ask me, how to install Business intelligence Development studio. Installing business intelligence
Development studio, is as simple as adding components to an existing SQL installation. Just run the SQL
setup again, and choose add features to an existing installation, and choose select the required features
you need.
Follow a step by step process to create your first Business Intelligence Report.
Step 1: Open Business Intelligence Development Studio (BIDS) (Start --> Microsoft SQL server 2008 -->
SQL server Business Intelligence studio
Step 2: Click File --> New project --> Report Server Project Wizard. Give any name and location.
Step 3: Once you click OK, you will be presented with the following screen.
Step 4: Click Next. Now configure your connection string. I have chosen the type as 'Microsoft SQL
server'
Step 5: In this step, you need to enter the query for the data, that you need the SSRS report to be
populated with. You can also use the query builder.
Step 6: Click on query builder, and click on the right most top icon, to add tables
Step 7: Select the necessary table, and verify your query, then click the (!) icon to see the result of the
query after execution.
Step 16: Now, Right click the project, and click deploy.
Step 17: After successfully deploying the project, open up IE, and hit http://machinename/reports
Alright, now we have published our first simple SSRS report using the Reporting Wizard. We deployed
the report, and viewed it via a web browser. Next, we will understand, how to develop reports, without
the custom report creation wizard. This will give much better control, over developing custom reports.
(Eg. you need to add custom calculations, embed maps etc.
When you fire up, Microsoft Business Intelligence Development studio - it looks like this.
The Left side portion, is where you set up your data connections, what parameters your report should
use, the queries that return data for your report etc.
The middle portion, is where you actually develop the report. Eg. Setup tabular reports, matrix reports
or embed maps, graphics etc
The Right side portion, is called the solution explorer. It lists down all reports (also called RDL's or report
definition language) to be displayed. Report definition languages are pure XML file.
Most of the report development that you do using Microsoft SQL server reporting services, would be
using the non-wizard method. This allows more flexibility to your report development.
Step 1: Open Microsoft Business Intelligence studio, and create a report server project.
Step 3: right click on the "Data sources" folder and add a new data source.
Set the connection string to point to your new adventure works database.
Step 4: Once that is done, right click on the datasets folder, to add a dataset.
This is basically the place, where you will configure your query that returns some data that you want to
be displayed in the report.
Select the datasource, that you just created and type in a query.
You could also use the "Query Designer" if you want.
After everything is done, click ok
Step 5: Now from the toolbox, drag and drop a table control.
Step 6: From the "Report Data", drag and drop the columns defined in the dataset that you want in the
report.
Step 7: That's it, click on the preview tab and congratulations, you have made your first Microsoft SQL
server report using a non-wizard method.
Lesson 7: Creating an SSRS parameterized report
We are going to expose the postal code as a parameter. This means, we will see the address of only the
entered postal code.
Step 3: Let’s explore more about the parameter. Double click on @postalcode.
This is place, where you configure, how your parameter should behave - should it allow blank values or
null values etc.
You can configure the visibility, data-types, default values etc.
Let’s leave it as it is for now.
Step 4: Click preview, and enter in a postal code (91370 for example)
Step 1: Create a report server project and connect to Adventure Works Database.
Step 2: Add the SalesOrderDetail table with a couple of columns to the Report.
Step 5: Now let’s write some expressions. We will display anything in LineTotal cell as Green, if the
number is above 2000, else we will display in Red.
Right click on the cell, and select text-box properties.
Step 6: Next to the color dropdown, there is an Fx button.
Write the below expression.
I have demonstrated a very simple use of expressions. However, you can write very complex expressions
depending on your business needs. For instance, you can write expressions, to calculate the standard
deviation of so and so, and manipulate results accordingly.
Many time, you need to write expressions to deal with Dates and times
for information on: http://msdn.microsoft.com/en-us/library/ms157328.aspx
Lesson 9: Creating a SSRS tabular report
Creating SSRS tabular reports, is one of the simplest and easiest task.
Tabular reports implies, just simple data representation using tables.
SSRS makes creating tabular report super simple - just drag and drop data elements.
It gives you the ability to add totals etc, as we do in excel.
Step 1:
Create an SSRS report server project.
Step 2:
Next add a blank report to your project.
Step 3:
Next we need to create a Dataset.
In the Report data tab, right click on Datasets and complete the wizard.
I am using Adventure works database for this demo.
Step 4: Add a query to get some data to your report.
Step 5: Now drag and drop a table control from the tool box (Left hand pane)
In the table control, drag and drop some fields from your dataset.
Once done, your Design pane should look something like this.
Step 6: Click on the preview tab, and you should be able to see a very basic tabular report.
Step 7: You could also add some totals to your report.
In order to add totals, right click on the cell where you would like to add the totals, click on 'Add Total'.
Click preview and you should be able to see a tabular report with totals.
Step 1:
Create a basic tabular report, using Adventure works database.
The report would look something like this.
Step 2:
In the design view, select the cells in the report, where you want to apply the formatting.
You could either use any of the shortcut keys (like cntrl + B, cntrl + I, cntrl + U) on you can use the icons
in the toolbar.
Similarly try adding some background color or text color.
Play around with bullets and numbering.
The same toolbar, also allows you to set the alignment of text.
Step 3:
Some of the features are given in the screenshot below.
Step 6: Now let’s play around with some Currency formatting and date formatting.
Right click on the unit price cell.
Click on text box properties.
On the left hand pane, click Number --> Currency
Step 7: Now let’s do some formatting for dates.
Right click on ModifiedDate --> Number --> Date
Step 8: After choosing your money and date format, click preview and report should look something like
this.
Lesson 11: SSRS grouping and totals
Many times we need to group the data in order to drill down further.
To put it simply, imagine you have a report which gives you sales amount for each of the continent.
You might want to drill down into each of these continents and see the sales amount for each country in
the continent.
Next, you might want to drill down further to see the sales amount for each state in a country.
Next you might want to drill down from yearly sales to say quarterly...and so on a so forth.
This is where we introduce Groups and drill downs If you have used the Group By clause, for
aggregation, you might know, what I am talking about.
In any case, let’s take an example from the adventure works database.
If you run the below query in SQL Server, you will get the following:
Query:
Let’s use this data in our report and group the data.
Then we will introduce drill through in our reports.
Step 1: Make a report, with a table control by dragging and dropping CustomerName, OrderNumber and
SalesAmount.
Hit preview - Your report should look something like this.
Step 2:
Now let’s add a product name, and let’s put the customer Name, order number and Sales Amount under
it.
Right click on the grouping area --> Add group --> Parent Group --> Group by 'Product Name' (Also Add a
group header)
let’s look at an example to use SSRS web services using Microsoft C#.
Step 1:
Create a Visual studio 2010 console application (you can use any Visual Studio version)
I am calling the application MyFirstSSRSWebService.
Step 2:
Next click add service reference:
Step 3:
Click advanced--> add web reference -- url - http://localhost/reportserver/reportservice2005.asmx
(replace localhost with your report server name).
Then click add reference
Step 4:
You should be seeing the SSRS webservice that you just added, in the solution explorer:
Step 5:
I have created a report called MyFirstReport in my local, and given it a small description.
Step 6:
Now let’s try to programmatically display this report name and the description
Copy paste the following c# code:
using System;
using MyFirstSSRSWebService.myPC;
namespace MyFirstSSRSWebService
{
class Program
{
static void Main(string[] args)
{
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://localhost/reportserver_SSRSexpress/reportservice2005.asmx";
try
{
Property[] returnProperties = rs.GetProperties(
"/HelloWorld/MyFirstReport", properties);
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
}
}
Step 7: Run the code, you should be seeing the following output
Likewise, I would encourage you to explore other methods of this web service as well.
One common activity people do, is to programmatically render a report in excel/pdf etc
Lesson 13: SSRS Subscriptions - Email Based
Step 4: Drag and drop the Matrix control from the ToolBox.
Step 5: Drag and drop the territory to the rows and Year to the column:
Step 6: ON clicking Preview, you should be able to get something like this:
Step 7: However the report, does not have any aggregated data.
So let’s drag and drop the TotalDue field to the 'Data' area in the report.
Step 8: On clicking preview, you should be able to see the aggregated report as below:
In this tutorial, let’s see how to add the drill down feature to an existing matrix report.
Let’s take the same matrix report, which we created in the last tutorial.
Let’s add some child groupings to this report, and explore some visibility toggling features.
Step 1: Right click on the Territory field and add a child group:
Step 2: Choose 'CountryRegionCode' to group by:
Step 5: Click on the row groups - 'CountryRegionRegion' and select the group properties:
Step 6: In the visibility pane, check 'Hide' for ‘when the report is initially run'
also, check the 'display can be toggled by this report item' for Territory
SSRS Subreports are extremely helpful, when we need to embed multiple reports in a single report.
The main report serves as a container for multiple sub-reports.
SSRS gives us complete control over what parameters to be passed to the sub report.
Many times this is useful in matrix reports too.
Step 1: Create a main report (Steps to create a basic report can be found in the previous tutorials)
I have the following dataset:
SELECT [TerritoryID]
,[Name]
,[CountryRegionCode]
,[Group]
,[SalesYTD]
,[SalesLastYear]
,[CostYTD]
,[CostLastYear]
,[rowguid]
,[ModifiedDate]
FROM [AdventureWorks].[Sales].[SalesTerritory]
Where CountryRegionCode = @CRC
Step 7:
Choose the parameters tab, and configure the parameters
Step 8: click OK and hit preview.
You should be able to see the main and the sub-report.
Lesson 18: Managing SSRS Security
As soon as you install SSRS 2008 R2, in your server and hit http:///reports, by default the the system
administrators get access to the report manager.
But if you wish to let other people see the reports that you deploy, you need to explicitly provide access
to these reports.
Providing access to reports is very simple and can be done at an item level (report level) or a folder level.
If you need to grant all users of your domain access, then you may need to add 'Domain\DomainUSERS'
and assign appropriate roles.
There are mainly 5 types of roles that you can assign to a user or a group.
These roles are:
a. Browser
b. Content Manager
C. My Reports
d. Publisher
e. Report Builder.
If you wish to add just a particular user of your domain for your report, type the username and select
the appropriate role for the same.
SSRS 2008R2 provides a rich set of visualization tools. Some of them are charts / graphs. These are
available in 3D formats to add a rich effects to your reports.
SSRS charts and graphs helps to summarize the data in visual format. It enables to represent very large
datasets as aggregated information available at a glance.
SSRS 2008 R2 also added sparklines to the visualization tools.
In addition, SSRS 2008 R2 also supports guages/Databasrs/Sparkline/Indicators.
Step 1:
As usual, let’s create a blank report, connecting to adventure works database with dataset:
Step 3: These are the set of shapes provided by SSRS for visualization purposes.
Choose the first shape.
You should be getting something like this on your screen:
Step 4: This is a blank chart, with no data in it.
You can click on the headings/text in the axis and change accordingly.
Alternatively, you can also write SSRS expressions to change text/descriptions dynamically.
Please refer my previous tutorial, on SSRS expressions.
Step 5: In the above example, i have changed the chart title to 'My First Chart'
Now drag and drop TotalDue to the summation of values, CountryRegionCode to the CategoryGroups
and year to the series Groups.
Something like this...
Step 6: Hit Preview, and you be getting something like this:
Lesson 21: SSRS 2008 R2 Document Maps
A document map in an SSRS report, provides pointers/links to certain report items in your report.
If you have a document map in your report, it will appear in the left most pane. Clicking on any of the
links, in the document pane, jumps the users directly to the report item.
It is similar to the table of contents.
Please note that clicking on the document map links, refreshes the report.
Your design view after creating the report should look something like this.
Please observe the Row groups.
Adding Territory as a group is necessary here, else SSRS will repeat the Territory values in the document
map.
You can hide one of the territory column (the non-group one) in the report.
Now hit preview, and you should be able to see the follow SSRS 2008 R2 report with a document map:
Select any one Territory in the document map, and the report will jump to the appropriate page.
Lesson 22: SSRS report execution and performance enhancements
1. On Demand.
2. From Cache
3. From Snapshots
On demand:
This is normal approach that we follow, by hitting a report server URL. Each time a report is run, data is
returned from the database server and rendered to the report.
This approach ensures that our report is update and fresh.
The downside of this approach is that, if n users open up this report on their browsers, queries on the
report are executed n times.
Thus this approach at times might slow down the server.
Cache
one of the performance enhancements techniques is to cache a report when it is initially run.
This means that if another user requests for the report, the same report is served to the user from the
cache
this avoids people querying the database server from each report rendering.
To make sure that people do not receive too much stale data, we can set a time to invalidate a cache.
This is a good performance enhancement technique for slow running reports.
Snapshots:
Report snapshots are created at a particular schedule for certain parameters.
Please note that parameters cannot be changes on snapshot reports.
SSRS 2008 R2 allows to schedule the snapshot creation times.
Users can directly render a report from a snapshot. However please note that not all reports can have
snapshots, especially the ones that prompt users for credentials.