SSRS Reporting Tutorials
SSRS Reporting Tutorials
In this set of tutorials, we will be learning microsoft sql server 2008 reporting services.
As far as possible we will use the adventure works database, which is available here. We
will also walk through various ms sql server 2008 tools. This set of tutorials,
is designed for anyone with absolutely no experience in business intelligence SSRS
or sql server reporting services. We will also walk through sql reporting services
configuration, creating your first report, deploying, security etc.
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, that helps you to create, deploy and manage
reports.
You can extend reporting functionality using C# and VB as programming
languages.
Microsoft SSRS or Business Intelligence SSRS, lets you create very rich reports
(Tabular/Graphical/Interactive/free-form) from various datasources with rich data
visualization (Charts, Maps, sparklines).
All these reports can be viewed via a web browsers.
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.
You can download some samples from here.
Next, lets look at how to install SSRS and get you started.
Lets 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 2: Right Click on the downloaded file and "Run as Administrator".
Step 4: In case you get a pop-up saying "This program has compatibility issues", click Run Program.
Step 7 : Select installation on right hand tab and click on "New SQL server stand -alone installation"
Step 13 : In feature selection, make sure you select 'Database Engine Services' and 'Reporting
Services'
Step 14 : Next, select Named Instance and give it any name (you can also choose Default instance)
Step 15 : Click next
Step 16 : Select Mixed Mode --> enter in any password --> and specify SQL server admins.
Step 17 : Click next, and select 'Install, but do not configure under Reporting Services configuration.
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)
Step 27: open IE and hit the noted down URL
That's all. We are all set. Let's install some sample databases and get started learning SSRS 2008
This video in YouTube, describes with a brief demo:
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
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 15 : You can preview the report in Business Intelligence Development Studio.
Step 17 : After successfully deploying the project, open up IE, and hit http://machinename/reports
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.
Pressing control+Alt+X brings up the toolbox.
Here you see a number of tools, that aid you in your report development. You simply need to drag
and drop the tools, that you need in your report, and then configure it accordingly.
We will have a look at some of them in the coming lessons.
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.
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.
Step 2: Once you click OK, go to the parameters folder in "Report Data" - you will find that
@postalcode automatically appears in the "Parameters" Fields.
Step 3: Lets 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.
Lets leave it as it is for now.
Step 4: Click preview, and enter in a postal code (91370 for example)
Hence, you can write expressions to manipulate the data, or change the properties of cell etc. Even if
you are dealing with graphs and maps, many of the properties, you can control using expressions
(like color of graph, some values etc).
Basically you would want to write expressions, if you need to manipulate properties/data at runtime
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 lets 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 9: Click on the preview tab, you should get the below output.
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
Thanks for reading my post, and let me know of your feedback
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.
Lets look at some basic steps to create a SSRS tabular report.
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 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.
SELECT
TOP (100) *
FROM
Sales.SalesOrderDetail
Step 5: Once you create a report, using the above query, your report would look something like this.
Step 6: Now lets 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 8: After choosing your money and date format, click preview and report should look something
like this.
,A.SalesOrderNumber AS [OrderNumber]
,A.SalesAmount
FROM FactInternetSales A
JOIN DimProduct B
ON B.ProductKey = A.ProductKey
JOIN DimCustomer C
ON C.CustomerKey = A.CustomerKey
JOIN DimDate D
ON D.DateKey = A.OrderDateKey
JOIN DimSalesTerritory ST
ON ST.SalesTerritoryKey = A.SalesTerritoryKey
Step 2:
Now lets Add a product name, and lets 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)
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 lets 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";
Property name = new Property();
name.Name = "Name";
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
Step 3: if the credentials are not stored, you will get the following error message.
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 lets 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:
Lets 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 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
Step 4: Now lets add a sub-report and pass in the same parameter to it.
Drag and drop a sub-report control from the toolbox.
Step 6: Lets us the previous tablix report that we created as our sub-report.
Step 7:
Choose the parameters tab, and configure the parameters
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 an user or a group.
These roles are:
a. Browser
b. Content Manager
c. My Reports
d. Publisher
e. Report Builder.
Descriptions for each of these roles are provided in the UI itself.
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.
Click OK, and your security is set.
Example:
Example:
)
GO
Stored procedures are group of SQL statements that are created previously and stored.
Stored procedures can accept parameters, and also have output parameters.
Permisions can be modifed for stored procedures.
Example:
WHERE B = @param
Example: http://www.youtube.com/watch?v=jx63oKvU8Iw
6. Give an example for Stored Procedures with parameters and output parameters.
CREATE PROCEDURE GetImmediateManager
@employeeID INT,
@managerID INT OUTPUT
AS
BEGIN
SELECT @managerID = ManagerID
FROM HumanResources.Employee
WHERE EmployeeID = @employeeID
END
Example:
http://www.youtube.com/watch?v=OO-AnA_52Og
data as files on the file system. Transact-SQL statements can insert, update, query, search, and back up
FILESTREAM data.
Example: http://www.youtube.com/watch?v=ONYjKN21aIw
Difference:
1. Stored Procedure can have output parameters UDF s cannot.
2. Stored Procedures return integers UDFs can return scalar or tables.
3. Stored procedures can have Insert/Delete/update Statement UDFs cannot
4. Stored Procedures are compiled at compile time UDFs are compiled at runtime.
5. Stored procedure cannot be used in the select/where/having clause UDFs can be
Example:
Stored procedures: https://www.youtube.com/watch?v=jx63oKvU8Iw
User Defined Functions: https://www.youtube.com/watch?v=vBg216_AODA
10. When do we use a having clause and when do we use a where clause?
Having Clause applies to groups hence used with groupby clause.
Where is applied row by row
Example:
SELECT A, AVG(B)
FROM some_table
GROUP BY A
HAVING AVG(B) >10
Types of triggers:
DDL trigger
DML trigger (instead of/after trigger)
Example:
CREATE TRIGGER T1
ON TABLE_NAME
AFTER INSERT
AS
BEGIN
ROLLBACK TRANSACTION
END
GO
16.Explain linked server with an example.
A Linked Server is a connection to an external data source. The remote data source can be DB2, Oracle,
Access or any other data source that uses an OLE DB provider.
Example:
Width sensitivity:When a single-byte character (half-width) and the same character when represented
as a double-byte character (full-width) are treated differently then it is width sensitive
Accent sensitivity: If a and , o and are treated in the same way, then it is accent-insensitive.
Case sensitivity: If A and a, B and b, etc. are treated in the same way then it is case-insensitive. SQL
distinguishes using ASCII values of A(65) and a(97)
Kana Sensitivity: When Japanese kana characters Hiragana and Katakana are treated differently, it is
called Kana sensitive
18.What is primary key/Unique Key and difference between them?
Primary key: The key of a relational table that uniquely identifies each record in the table. Primary
Key doesnt allow NULLS
Clustered Indexes are created on Primary Keys.
Unique Key: Unique Key enforces uniqueness of the column on which they are defined. Unique Key
allows one NULL value
Non-Clustered indexes are created on Unique Keys.
19.Explain 1:1, 1:m, m:m relationships1:1 -In a one-to-one relationship, a row in table A can have no
more than one matching row in table B, and vice versa. A one-to-one relationship is created if both of the
related columns are primary keys or have unique constraints.
1:many In 1:many type of relationship, a row in table A can have many matching rows in table B, but a
row in table B can have only one matching row in table A.
many:many: In a many-to-many relationship, a row in table A can have many matching rows in table B,
and vice versa. 20.Explain delete and truncate statement and the differenceDelete: The DELETE
Statement is used to delete rows from a table.
DELETE is a logged operation on a per row basis
Example:
DELETE FROM table_name [WHERE condition];
Truncate: The TRUNCATE command is used to delete all the rows from the table and free the space
containing the table
An index can be created in a table to find data more quickly and efficiently. it is a structure within SQL that
is used to quickly locate specific rows within a table.
CLUSTERED INDEX: Clustered indexes define the logical order of the table. The leaf level of the
clustered index has the actual data pages of the table. Because of this there can only be one clustered
index per table.
A table that does not have a clustered index is referred to as a heap
NON-CLUSTERED INDEX: Here, the leaf level of a nonclustered index has a pointer as part of each
index row. That pointer is either the clustered index key in the cases where the base table has a clustered
index or the Row Identifier in the cases where the table is a heap
23.Difference between char and nvarchar / char and varchar data-type?
char [ ( n ) ] : Fixed-length, non-Unicode string data. n defines the string length and must be a value from
1 through 8,000. The storage size is n bytes.
varchar [ ( n | max ) ] : Variable-length, non-Unicode string data. n defines the string length and can be a
value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
nvarchar [ ( n | max ) ] : Variable-length Unicode string data. n defines the string length and can be a
value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
24.What are joins? What are the different types of joins?
Joins are used to query data from more than 2 tables, based on a relationship between columns in these
tables.
JOIN: Return rows when there is at least one match in both tables.
LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
FULL JOIN: Return rows when there is a match in one of the tables
Step 2:
Now lets drag and drop a chart control from the toolbox.
As soon as you do that , you get a pop-up, displaying various image shapes for the chart control.
Step 3: These are the set of shapes provided by SSRS for visualization purposes.
Let's choose the first shape.
You should be getting something like this on your scree:
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 7: Try these steps, with a number of other shapes and graphs/Sparklines/Indicators.
Your design view after creating the report should look something like this.
Now hit preview, and you should be ale 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.
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:
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.