0% found this document useful (0 votes)
113 views

SSRS Tutorials - SQL Server Reporting Service

This tutorial provides steps to create a basic table report in SQL Server Reporting Services (SSRS) using Visual Studio and the AdventureWorks2014 sample database. It describes how to: 1. Create a report server project in Visual Studio to contain the report files. 2. Specify a data connection to the AdventureWorks2014 database to use as the data source for the report. 3. Define a dataset query that retrieves sales order information from tables in the AdventureWorks2014 database to populate the report.

Uploaded by

K T
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

SSRS Tutorials - SQL Server Reporting Service

This tutorial provides steps to create a basic table report in SQL Server Reporting Services (SSRS) using Visual Studio and the AdventureWorks2014 sample database. It describes how to: 1. Create a report server project in Visual Studio to contain the report files. 2. Specify a data connection to the AdventureWorks2014 database to use as the data source for the report. 3. Define a dataset query that retrieves sales order information from tables in the AdventureWorks2014 database to populate the report.

Uploaded by

K T
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Reporting Services Tutorials (SSRS)

Applies To: SQL Server 2016

This section contains tutorials for SQL Server 2016 Reporting Services (SSRS).

Create a Basic Table Report (SSRS Tutorial)


Follow the steps in this tutorial to learn how to create your first report. This tutorial shows
you how to work with SQL Server Data Tools (SSDT) to create a data connection (data
source), define a simple query (dataset), and configure a data region to contain your data.

Create a Data-Driven Subscription (SSRS Tutorial)


Reporting Services provides data-driven subscriptions so that you can customize the
distribution of a report based on dynamic list of subscribers that will receive the report. Data-
driven subscriptions are typically created and maintained by report server administrators. The
ability to create data-driven subscriptions requires expertise in building queries, knowledge of
data sources that contain subscriber data, and elevated permissions on a report server.

Accessing the Report Server Web Service Using Visual Basic or Visual C# (SSRS Tutorial)
Follow the steps in this tutorial to learn how to access the SQL Server 2016 Reporting
Services (SSRS) Web services from an application created with Microsoft Visual Basic or
Microsoft Visual C#.

Updating Reports Using Classes Generated from the RDL Schema (SSRS Tutorial)
Follow the steps in this tutorial to learn how to use the XML Schema Definition Tool
(Xsd.exe) to generate classes that allow you to serialize and deserialize report definition files
(.rdl and .rdlc) with the Microsoft .NET Framework.

Create a Drillthrough (RDLC) Report with Parameters using ReportViewer (SSRS Tutorial)
Follow the steps in this tutorial to learn how to create a drillthrough report with parameters
and a filter using the ReportViewer control.

Report Builder Tutorials


Tutorials to help you use Report Builder create rich reports that contain data visualizations
such as Maps and Sparklines as well as tutorials on how to use parameters and expressions.
Create a Basic Table Report
(SSRS Tutorial)

Updated: April 18, 2016

Applies To: SQL Server 2016

This tutorial is designed to help you create a basic table report based on the
AdventureWorks2014 database using Report Designer. You can also use Report Builder or
the Report Wizard to create reports. In this tutorial, you will create a report project, set up
connection information, define a query, add a Table data region, group and total some fields,
and preview the report.

Requirements

Your system must have the following installed to use this tutorial:

• Microsoft SQL Server 2016 database engine.


• SQL Server 2016 Reporting Services (SSRS) in native mode.
• The AdventureWorks2014 database. For more information, see Adventure Works
2014 Sample Databases).
• SQL Server Data Tools with the "SQL Server Reporting Services" components
installed so you have the Report Designer.

You must also have read-only permissions to retrieve data from the AdventureWorks2014
database.

Tasks

Lesson 1: Creating a Report Server Project (Reporting Services)

Lesson 2: Specifying Connection Information (Reporting Services)

Lesson 3: Defining a Dataset for the Table Report (Reporting Services)

Lesson 4: Adding a Table to the Report (Reporting Services)

Lesson 5: Formatting a Report (Reporting Services)

Lesson 6: Adding Grouping and Totals (Reporting Services)


Lesson 1: Creating a Report Server Project
(Reporting Services)
Updated: April 15, 2016, Applies To: SQL Server 2016

To create a report with SQL Server Data Tools (SSDT) , first create a report server project
where you will save your report definition (.rdl) file and any other resource files that you
need for your report. Then you will create the, define a data source for your report, define a
dataset, and define the report layout. When you run the report, the data is retrieved and
combined with the layout, and then rendered on your screen, from where you can export it,
print it, or save it.

In this lesson, you will learn how to create a report server project in SQL Server Data Tools.
A report server project is used to create reports that run on a report server.

To create a report server project

1. Open SQL Server Data Tools.


2. On the File menu, point to New, and then click Project.
3. In the Installed Templates list, click Business Intelligence.
4. Click Report Server Project . If you do not see the "Business Intelligence" or
""Report Server Project" options, you need to update SSDT with the Business
Intelligence temapltes. See Download SQL Server Data Tools (SSDT)
5. In Name, type Tutorial.
6. Click OK to create the project.

The Tutorial project is displayed in Solution Explorer.

To create a new report definition file

1. In Solution Explorer, right-click Reports, point to Add, and click New Item. If the
Solution Explorer window is not visible, from the View menu, click Solution
Explorer.

2. In the Add New Item window, click Report .


3. In Name, type Sales Orders.rdl and then click Add.

Report Designer opens and displays the new .rdl file in Design view.
Report Designer is a Reporting Services component that runs in SQL Server Data Tools
(SSDT). It has two views: Design and Preview. Click each tab to change views.

You define your data in the Report Data pane. You define your report layout in Design
view. You can run the report and see what it looks like in Preview view.

You have successfully created a report project called "Tutorial" and added a report definition
(.rdl) file to the report project. Next, you will specify a data source to use for the report.
Lesson 2: Specifying Connection
Information (Reporting Services)
Updated: April 18, 2016, Applies To: SQL Server 2016

After you add a report to the Tutorial project, you need to define a data source, which is
connection information the report uses to access data from either a relational database,
multidimensional database, or other resource.

In this lesson, you will use the AdventureWorks2014 sample database as your data source.
This tutorial assumes that this database is located in a default instance of SQL
Server Database Engine that is installed on your local computer.

To set up a connection

1. In the Report Data pane, click New and then click Data Source….
If the Report Data pane is not visible, from the View menu, click Report Data.
2. In Name, type AdventureWorks2014 database.
3. Make sure Embedded connection is selected.
4. In Type, select Microsoft SQL Server.
5. In Connection string, type the following:
6. Data source=localhost; initial catalog=AdventureWorks2014
7.

This connection string assumes that SQL Server Data Tools (SSDT), the report server,
and the AdventureWorks2014 database are all installed on the local computer and
that you have permission to log on to the AdventureWorks2014 database.

Note

If you are using SQL Server Express with Advanced Services or a named instance,
the connection string must include instance information:

Data source=localhost\SQLEXPRESS; initial catalog=AdventureWorks2014

For more information about connection strings, see:

o Data Connections, Data Sources, and Connection Strings in Reporting


Services
o Data Source Properties Dialog Box, General

6. Click Credentials in the left pane and click Use Windows Authentication
(integrated security).
7. Click OK. The data source SQL Server Data Tools (SSDT) is added to the Report
Data pane.
You have successfully defined a connection to the AdventureWorks2014 sample database.
Next, you will create the report

Lesson 3: Defining a Dataset for the Table


Report (Reporting Services)
Updated: April 18, 2016

Applies To: SQL Server 2016

After you define the data source, you need to define a dataset. In Reporting Services, data
that you use in reports is contained in a dataset. A dataset includes a pointer to a data source
and a query to be used by the report, as well as calculated fields and variables.

Use the query designer in Report Designer to design the dataset. For this tutorial, you will
create a query that retrieves sales order information from the AdventureWorks2014
database.

To define a Transact-SQL query for report data

1. In the Report Data pane, click New, and then click Dataset…. The Dataset
Properties dialog box opens.
2. In the Name box, type AdventureWorksDataset.
3. Click Use a dataset embedded in my report.
4. Select the data souce you created, AdventureWorks2014.
5. Select Text for the Query type.
6. Type, or copy and paste, the following Transact-SQL query into the Query box.
7. SELECT
8. soh.OrderDate AS [Date],
9. soh.SalesOrderNumber AS [Order],
10. pps.Name AS Subcat, pp.Name as Product,
11. SUM(sd.OrderQty) AS Qty,
12. SUM(sd.LineTotal) AS LineTotal
13. FROM Sales.SalesPerson sp
14. INNER JOIN Sales.SalesOrderHeader AS soh
15. ON sp.BusinessEntityID = soh.SalesPersonID
16. INNER JOIN Sales.SalesOrderDetail AS sd
17. ON sd.SalesOrderID = soh.SalesOrderID
18. INNER JOIN Production.Product AS pp
19. ON sd.ProductID = pp.ProductID
20. INNER JOIN Production.ProductSubcategory AS pps
21. ON pp.ProductSubcategoryID = pps.ProductSubcategoryID
22. INNER JOIN Production.ProductCategory AS ppc
23. ON ppc.ProductCategoryID = pps.ProductCategoryID
24. GROUP BY ppc.Name, soh.OrderDate, soh.SalesOrderNumber, pps.Name,
pp.Name,
25. soh.SalesPersonID
26. HAVING ppc.Name = 'Clothing'
27.
28. (Optional) Click the Query Designer button. The query is displayed in the text-based
query designer. You can toggle to the graphical query designer by clicking Edit As
Text. View the results of the query by clicking the run button on the query
designer toolbar.

You see the data from six fields from four different tables in the
AdventureWorks2014 database. The query makes use of Transact-SQL functionality
such as aliases. For example, the SalesOrderHeader table is called soh.

Click OK to exit the query designer.

29. Click OK to exit the Dataset Properties dialog box.

Your AdventureWorksDataset dataset and fields appear in the Report Data pane.

You have successfully specified a query that retrieves data for your report. Next, you will
create the report layout.
Lesson 4: Adding a Table to the Report
(Reporting Services)
Updated: April 18, 2016

Applies To: SQL Server 2016

After the dataset is defined, you can start designing the report. You create a report layout by
dragging and dropping data regions, text boxes, images, and other items that you want to
include in your report to the design surface.

Items that contain repeated rows of data from underlying datasets are called data regions. A
basic report will have only one data region, but you can add more, for example, if you want
to add a chart to your tabular report. After you add a data region, you can add fields to the
data region.

To add a Table data region and fields to a report layout

1. In the Toolbox, click Table, and then click on the design surface and drag the mouse.
Report Designer draws a table data region with three columns in the center of the
design surface. The Toolbox may appear as a tab on the left side of the Report Data
pane. To open the Toolbox, move the pointer over the Toolbox tab. If the Toolbox is
not visible, from the View menu, click Toolbox
o You could also right-click the design surface, click Insert and then click
Table.
2. In the Report Data pane, expand the AdventureWorksDataset dataset to display the
fields.
3. Drag the Date field from the Report Data pane to the first column in the table.

When you drop the field into the first column, two things happen. First, the data cell
will display the field name, known as the field expression, in brackets: [Date].
Second, a column header value is automatically added to Header row, just above the
field expression. By default, the column is the name of the field. You can select the
Header row text and type a new name.

4. Drag the Order field from the Report Data pane to the second column in the table.
5. Drag the Product field from the Report Data pane to the third column in the table.
6. Drag the Qty field to the right edge of the third column until you get a vertical cursor
and the mouse pointer has a plus sign [+]. When you release the mouse button, a
fourth column is created for [Qty].

7. Add the LineTotal field in the same way, creating a fifth column. The column header
is Line Total. Report Designer automatically creates a friendly name for the column
by splitting LineTotal into two words.
The following diagram shows a table data region that has been populated
with these fields: Date, Order, Product, Qty, and Line Total.

Preview Your Report

Previewing a report enables you to view the rendered report without having to first publish it
to a report server. You will probably want to preview your report frequently during design
time. Previewing the report will also run validation on the design and data connections so you
can correct errors and issues before publishing the report to a report server.

To preview a report

• Click the Preview tab. Report Designer runs the report and displays it in Preview
view.

The following diagram shows part of the report in Preview view.

Notice that the currency (in the Line Total column) has six places after the decimal,
and the date has includes a time stamp. You're going to fix that formatting in the next
lesson.

Note

On the File menu, click Save All to save the report.

Next Steps

You have successfully added a Table data region to your report, added fields to the data
region, and previewed your report. Next, you will format column headers and date and
currency values.
Lesson 5: Formatting a Report (Reporting
Services)

Updated: April 18, 2016

Applies To: SQL Server 2016

Now that you've added a data region and some fields to the Sales Orders report, you can
format the date and currency fields and the column headers.

Format the Date

The Date field displays date and time information by default. You can format it to display
only the date.

To format a date field

1. Click the Design tab.


2. Right-click the cell with the [Date] field expression and then click Text Box
Properties.
3. Click Number, and then in the Category field, click Date.
4. In the Type box, select January 31, 2000.
5. Click OK.
6. Preview the report to see the change to the [Date] field and then change back to
design view.

Format the Currency

The LineTotal field displays a general number. Format it to display the number as currency.

To format a currency field

1. Right-click the cell with the [LineTotal] field expression and then click Text Box
Properties.
2. Click Number, and in the Category field, click Currency.
3. If your regional setting is English (United States), the defaults should be:
o Decimal places: 2
o Negative numbers: ($12345.00)
o Symbol: $ English (United States)
4. Select Use 1000 separator (,).

If the sample text is:$12,345.00, then your settings are correct.

5. Click OK.
6. Preview the report to see the change to the [LineTotal] field and then change back
to design view.

Change Text Style and Column Widths

You can also change the formatting of the header row to differentiate it from the rows of data
in the report. Lastly, you will adjust the widths of the columns.

To format header rows and table columns

1. Click the table so that column and row handles appear above and next to the table.
The gray bars along the top and side of the table are the column and row handles.

2. Point to the line between column handles so that the cursor changes into a double
arrow. Drag the columns to the size you want.
3. Select the row containing column header labels and from the Format menu, point to
Font and then click Bold.
4. To preview your report, click the Preview tab. It should look something like this:

5. On the File menu, click Save All to save the report.

Next Steps

You have successfully formatted column headers and date and currency values. Next, you
will add grouping and totals to your report.
Lesson 6: Adding Grouping and Totals
(Reporting Services)

Updated: April 18, 2016

Applies To: SQL Server 2016

Add grouping and totals to your Reporting Services report to organize and summarize your
data.

For information about adding running totals to reports, see this curation on
curah.microsoft.com: Adding totals to Reporting Services (SSRS) reports.

To group data in a report

1. Click the Design tab.


2. If you do not see the Row Groups pane , right-click the design surface and click view
and then click Grouping.
3. From the Report Data pane, drag the Date field to the Row Groups pane. Place it
above the row called (Details).

Note that the row handle now has a bracket in it, to show a group. The table now also
has two Date columns -- one on either side of a vertical dotted line.

4. From the Report Data pane, drag the Order field to the Row Groups pane. Place it
below Date and above (Details).

Note that the row handle now has two brackets in it, to show two groups. The table
now has two Order columns, too.

5. Delete the original Date and Order columns to the right of the double line. This
removes this individual record values so that only the group value is displayed. Select
the column handles for the two columns, right-click and click Delete Columns.
6. To format the new date column, Right-click the cell with the [Date] field expression
and then click Text Box Properties.
7. Click Number, and then in the Category field, click Date.
8. In the Type box, select January 31, 2000.
9. Click OK..
10. Switch to the Preview tab to preview the report. It should look similar to the
following illustration:

To add totals to a report

1. Switch to Design view.


2. Right-click the data region cell that contains the field [LineTotal], and click Add
Total.

This adds a row with a sum of the dollar amount for each order.

3. Right-click the cell that contains the field [Qty], and click Add Total.

This adds a sum of the quantity for each order to the totals row.

4. In the empty cell to the left of Sum[Qty], type the label "Order Total".
5. You can add a background color to the totals row. Select the two sum cells and the
label cell.
6. On the Format menu, click Background Color, click Light Gray, and click OK.
To add a daily total to a report

1. Right-click the Order cell, point to Add Total, and click After.

This adds a new row containing sums of the quantity and dollar amount for each day,
and the label "Total" to the bottom of the Order column.

2. Type the word Daily before the word Total in the same cell, so it reads Daily Total.
3. Select the Daily Total cell, the two Sum cells and the empty cell between them.
4. On the Format menu, click Background Color, click Orange, and click OK.

To add a grand total to a report

1. Right-click the Date cell, point to Add Total, and click After.

This adds a new row containing sums of the quantity and dollar amount for the entire
report, and the Total label in the Date column.

2. Type the word Grand before the word Total in the same cell, so it reads Grand
Total.
3. Select the Grand Total cell, the two Sum cells and the empty cells between them.
4. On the Format menu, click Background Color, click Light Blue, and click OK.

5. Click Preview.

The last page should look something like this:


To Publish the Report to the Report Server (Optional)

1. An optional step is to publish the completed report to the native mode report server so
you can view the report from Report Manager.
2. Click the Project menu and then click tutorial Properties...
3. In the TargetServerURL type the name of your report server, for example

• http:/<servername>/reportserver
• http://localhost/reportserver works if your designing the report on the report
server.

4. Note the TargetReportFolder is tutorial, the name of the project. This is the name of
the folder that the report will deploy to in later steps.
5. Click OK
6. On click the Build menu and then click Deploy tutorial.

If you see a message similar to the following in the output window, it indicates a
successful deployment.

------ Build started: Project: tutorial, Configuration: Debug ------


Skipping 'Sales Orders.rdl'. Item is up to date.
Build complete -- 0 errors, 0 warnings
------ Deploy started: Project: tutorial, Configuration: Debug ------
Deploying to http://[server name]/reportserver
Deploying report '/tutorial/Sales Orders'.
Deploy complete -- 0 errors, 0 warnings
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

If you see an error message similar to the following, verify you have permissions on
the report server and you have started SQL Server Data Tools with administrator
privileges.

"The permissions granted to user 'XXXXXXXX\[your user name]' are insufficient for
performing this operation"

7. Start Report Manager with administrator privileges, for example, right-click the icon
for Internet Explorer and click Run as administrator.

Browse to the Report Manager URL.


Note: The Report Manager URL is "Reports", not the Report Server URL of
"Reportserver". For example:

o http://<server name>/reports.
o http://localhost/reports works if your designing the report on the report
server.
8. Browse to the folder that contains the report. The default name is tutorial, the name of
the project or the name you typed into the TargetReportFolder fiedl in the project
properties.
Click the name of the report Sales Orders to view the rendered report in the browser.

Next Steps

You have successfully completed the Creating a Basic Table Report tutorial.

You might also like