Sunteți pe pagina 1din 3

Lesson 3: Defining a Dataset for the Table

Report Reporting Services


SQL Server 2016 and later

Updated: May 23, 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 in the previous lesson, AdventureWorks2014.
5. Select Text for the Query type.
6. Type, or copy and paste, the following TransactSQL query into the Query box.

SELECT
soh.OrderDateAS[Date],
soh.SalesOrderNumberAS[Order],
pps.NameASSubcat,pp.NameasProduct,
SUM(sd.OrderQty)ASQty,
SUM(sd.LineTotal)ASLineTotal
FROMSales.SalesPersonsp
INNERJOINSales.SalesOrderHeaderASsoh
ONsp.BusinessEntityID=soh.SalesPersonID
INNERJOINSales.SalesOrderDetailASsd
ONsd.SalesOrderID=soh.SalesOrderID
INNERJOINProduction.ProductASpp
ONsd.ProductID=pp.ProductID
INNERJOINProduction.ProductSubcategoryASpps
ONpp.ProductSubcategoryID=pps.ProductSubcategoryID
INNERJOINProduction.ProductCategoryASppc
ONppc.ProductCategoryID=pps.ProductCategoryID
GROUPBYppc.Name,soh.OrderDate,soh.SalesOrderNumber,pps.Name,pp.Name,
soh.SalesPersonID

HAVINGppc.Name='Clothing'

7. Optional Click the Query Designer button. The query is displayed in the textbased 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
query designer toolbar.

button on the

You see the data from six fields from four different tables in the AdventureWorks2014 database. The query makes use of
TransactSQL functionality such as aliases. For example, the SalesOrderHeader table is called soh.
8. Click OK to exit the query designer.
9. Click OK to exit the Dataset Properties dialog box.
Your AdventureWorksDataset dataset and fields appear in the Report Data pane.

Next Task
You have successfully specified a query that retrieves data for your report. Next, you will create the report layout. See Lesson 4:
Adding a Table to the Report Reporting Services.

See Also
Query Design Tools SSRS
SQL Server Connection Type SSRS
Tutorial: Writing TransactSQL Statements

Community Additions

Spotted a typo
4. Select the data souce you created in the previous lesson,
AdventureWorks2014
.

Correct "souce" to "source"


adaezeopara
12/6/2016

2016 Microsoft

S-ar putea să vă placă și