+ All Categories
Home > Documents > Reporting Services

Reporting Services

Date post: 30-Oct-2014
Category:
Upload: manasa-soppimath
View: 30 times
Download: 4 times
Share this document with a friend
Description:
Excercise on reporting services
Popular Tags:
54
Reporting Services Exercise I DESIGNING REPORTS EXERCISE1: S TEPS : Create a data set with the Query below Which retrieves Product Category, sub category, Year, Quarter, Month wise sales from ProductSubCategory, SalesOrderHeader, SalesTerritory, SalesOrderDetail tables in AdventureWorks database for period of 2002 and 2003: SELECT PC.Name AS ProdCat, PS.Name AS SubCat, DATEPART(yy, SH.OrderDate) AS OrderYear, 'Q' + DATENAME(qq, SH.OrderDate) AS OrderQtr, DATENAME(mm, SH.OrderDate) AS OrderMonth, ST.Name as Country, SUM(SO.UnitPrice * SO.OrderQty) AS Sales FROM PRODUCTION.ProductSubCategory PS INNER JOIN SALES.SalesOrderHeader SH INNER JOIN SALES.SalesOrderDetail SO ON SH.SalesOrderID = SO.SalesOrderID INNER JOIN SALES.SalesTerritory ST ON SH.TerritoryID = ST.TerritoryID INNER JOIN PRODUCTION.Product P ON SO.ProductID = P.ProductID ON PS.ProductSubCategoryID = P.ProductSubCategoryID INNER JOIN 1
Transcript
Page 1: Reporting Services

Reporting Services

Exercise

I DESIGNING REPORTS

EXERCISE1:

STEPS:

▪ Create a data set with the Query below

Which retrieves Product Category, sub category, Year, Quarter,

Month wise sales from ProductSubCategory, SalesOrderHeader,

SalesTerritory, SalesOrderDetail tables in AdventureWorks database

for period of 2002 and 2003:

SELECT PC.Name AS ProdCat, PS.Name AS SubCat, DATEPART(yy, SH.OrderDate) AS OrderYear, 'Q' + DATENAME(qq, SH.OrderDate) AS OrderQtr, DATENAME(mm, SH.OrderDate) AS OrderMonth, ST.Name as Country, SUM(SO.UnitPrice * SO.OrderQty) AS SalesFROM PRODUCTION.ProductSubCategory PS INNER JOIN SALES.SalesOrderHeader SH INNER JOIN SALES.SalesOrderDetail SO ON SH.SalesOrderID = SO.SalesOrderID INNER JOIN SALES.SalesTerritory ST ON SH.TerritoryID = ST.TerritoryID INNER JOIN PRODUCTION.Product P ON SO.ProductID = P.ProductID ON PS.ProductSubCategoryID = P.ProductSubCategoryID INNER JOIN PRODUCTION.ProductCategory PC ON PS.ProductCategoryID = PC.ProductCategoryIDWHERE (SH.OrderDate BETWEEN '1/1/02' AND '12/31/03')GROUP BY DATEPART(yy, SH.OrderDate), PC.Name, PS.Name, 'Q' + DATENAME(qq, SH.OrderDate), DATENAME(mm, SH.OrderDate), ST.Name, PS.ProductSubCategoryID

▪ Using Toolbox, Add a Matrix Design Layout

1

Page 2: Reporting Services

Reporting Services

Exercise

▪ Add ProdCat, SubCat fields to row group in the Matrix

▪ Add OrderYear, OrderQtr, OrderMonth, Country fields to column

group in the Matrix

▪ Add sales field to Details group in the matrix

▪ For all the rows and columns, Change the Name property

appropriately.

GROUPING

F IELD INITIAL VISIBILITY

PROPERTY

WHETHER CAB BE

TOGGED BY ANOTHER

PRODUCT ITEM AND IF

YES, THE REPORT

ITEM

ProductCat Visible -

Subcat Hidden ProductCat

OrderYear Visible -

OrderQtr Hidden OrderYear

OrderMonth Hidden OrderQtr

2

Page 3: Reporting Services

Reporting Services

Exercise

Country Hidden OrderMonth

SORTING

▪ SORT the “OrderQtr” by Ascending.

ADD BACKGROUND

PROPERTY SUB PROPERTY VALUE

Prerequisite task Drag and drop

Image item from

Toolbox

Background Image Source

Value

Embedded

Chose Embedded

image using the

image Wizard

Note: Delete the

image control

placed on the

report layout,

after you set the

Background

3

Page 4: Reporting Services

Reporting Services

Exercise

Source and Value

FORMAT

FORMAT VALUE

Add Border Style & Color to entire matrix Solid & Black

Assign background Color for each text box in

the matrix

Yellow

Assign Border for each text box in the matrix Solid

Drag and drop a text box on top of the matrix

report

Name of the

Report

ProductCat Text Align: Left

SubCat Text Align :

Right

OrderYear, OrderQtr, OrderMonth, Country,

Sales

Text Align:

Center

▪ Preview the Report

▪ Sort : quarter, month and country

4

Page 5: Reporting Services

Reporting Services

Exercise

▪ Remove OrderQtr from Matrix

▪ Remove OrderMonth

▪ Remove the image

EXERCISE 2:

STEPS:

▪ Create a Employee dataset with the following query:

Select c.firstname, c.lastname, e.title, d.departmentIDFrom HumanResources.EmployeeDepartmentHistory D INNER JOINHumanResources.Employee E ON D.EmployeeID = E.EmployeeID INNER JOINPerson.Contact C ON E.ContactID = C.ContactIDWhere D.DepartmentID=1Order By c.lastname

▪ Create a Department dataset with the following query:

SELECT 0 AS DepartmentID, 'All' AS NameUNIONSELECT DepartmentID, NameFROM HumanResources.DepartmentORDER BY Name

5

Page 6: Reporting Services

Reporting Services

Exercise

▪ Add a Table in the layout view placing the following fields from the

first data set in Detail Area:

FirstName

LastName

Title

▪ Using the menu option Report ->ReportParameters, create a report

parameter with the following properties set:

Name:Department

Data Type: String

Prompt: Deparment

Allow null value , Allow blank value : False

For Available values, select From query.

o Dataset: Departments

o Value field: DepartmentID

o Label f ield: Name.

▪ Modify the Employee dataset as follows:

="SELECT c.firstname, c.lastname, e.title, d.departmentID " &

"From HumanResources.EmployeeDepartmentHistory D " &

"INNER JOIN HumanResources.Employee E " &

"ON D.EmployeeID = E.EmployeeID " &

"INNER JOIN Person.Contact C " &

6

Page 7: Reporting Services

Reporting Services

Exercise

"ON E.ContactID = C.ContactID " &

Iif(Parameters!Department.Value = 0, "", "WHERE D.DepartmentID = " & Parameters!

Department.Value) &

"ORDER BY C.LastName"

▪ Preview the report – the query will use the report parameter.

EXERCISE 3:

STEPS:

▪ Create a dataset with the following query:

Which retrieves product wise, quantity sold from product,

SalesOrderDetail, and SalesOrderheader tables

SELECT Production.Product.Name, SUM(Sales.SalesOrderDetail.OrderQty) AS [ Quantity Sold ], DATEPART(yy, Sales.SalesOrderHeader.OrderDate) AS YearFROM Production.Product INNER JOIN Sales.SalesOrderDetail ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID INNER JOIN Sales.SalesOrderHeader ON Sales.SalesOrderHeader.SalesOrderID = Sales.SalesOrderDetail.SalesOrderIDGROUP BY DATEPART(yy, Sales.SalesOrderHeader.OrderDate), Production.Product.Name

▪ Add a table to Design Layout.

▪ Drag and drop the 3 fields in the Detail Area: Name, year and

Quantity

7

Page 8: Reporting Services

Reporting Services

Exercise

▪ Add Itemname field to grouping table properties.

GROUPING

F IELD PROPERTY

ItemName

(Header)

Select the following:

Include group header

Include group footer

Page Break at end

Repeat group header

Repeat group footer

Year of Sale

(header)

Select the following:

Include group header

Include group footer

ID_Quantity_Sol

d (Table Footer)

Drag the ID_Quantity_Sold field to the Table Footer area in the same column where ID_Quantity_Sold Column is present. This adds the following expression: =Sum(Fields!ID_Quantity_Sold_.Value)

FORMAT

8

Page 9: Reporting Services

Reporting Services

Exercise

FORMAT VALUE

Add Border & Color to entire

Table

Solid & Black

Text Alignment in the Table Center

Data Sorting Year

Assign color & make the font bold

for Table Group Header

Orange

▪ To add Page Numbers in page footers : Naviagte menu Report-

>Page Footer.This adds the Footer area in the layout. Drag and

drop a text box in the footer and set Expression: ="Page : ” &

Globals!PageNumber” . (To do this, set the Value property of the text box).

▪ Right-click a column heading for the year column. Navigate ->

properties -> interactive sort->Select Add an interactive sort

action to this text box. Specify the sort expressions as Year.

▪ Choose the data region to sort ( Table).

▪ Preview the report. Check that the effect of GroupHeader is not

visible. Check the effect of Interactive sort.

▪ Add conditional format – Set Expression in Font Property of

Quantity Sold Textbox using expression like this: =iif(Fields!

ID_Quantity_Sold_.Value < 300, "Red", "Black")

9

Page 10: Reporting Services

Reporting Services

Exercise

▪ Add Item Name to table group header and remove it from the

Details. This will ensure that Item name is displayed only once as

Group Header.

▪ Clear “Page Break At End” checkbox and drag and drop Quantity

field Name Footer (under the Quantity Column) . This will display

itemwise totals whenever item changes.

EXERCISE 4:

▪ Create dataset named SalesEmployees that uses an

AdventureWorks data source that gives EmployeeId and LoginID.

SELECT HumanResources.Employee.EmployeeID, HumanResources.Employee.LoginID AS EmployeeFROM HumanResources.Employee INNER JOIN Sales.SalesPerson ON HumanResources.Employee.EmployeeID = Sales.SalesPerson.SalesPersonIDORDER BY HumanResources.Employee.LoginID

▪ Create a second dataset named EmplSalesMonth that uses an

AdventureWorks data source giving the sales details for a given

employee for that month and year.

SELECT HumanResources.Employee.LoginID AS Employee, DATEPART(Year, Sales.SalesOrderHeader.OrderDate) AS OrderYear, DATEPART(Month, Sales.SalesOrderHeader.OrderDate) AS OrderMonthNum, DATENAME(Month, Sales.SalesOrderHeader.OrderDate) AS OrderMonth, Production.ProductCategory.Name AS ProdCat, SUM(Sales.SalesOrderDetail.LineTotal) AS SalesFROM Sales.SalesOrderHeader INNER JOIN Sales.SalesOrderDetail ON Sales.SalesOrderHeader.SalesOrderID = Sales.SalesOrderDetail.SalesOrderID INNER JOIN

10

Page 11: Reporting Services

Reporting Services

Exercise

Sales.SalesPerson ON Sales.SalesOrderHeader.SalesPersonID = Sales.SalesPerson.SalesPersonID INNER JOIN HumanResources.Employee ON Sales.SalesPerson.SalesPersonID = HumanResources.Employee.EmployeeID INNER JOIN Production.Product ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID INNER JOIN Production.ProductSubcategory ON Production.Product.ProductSubcategoryID = Production.ProductSubcategory.ProductSubcategoryID INNER JOIN Production.ProductCategory ON Production.ProductSubcategory.ProductCategoryID = Production.ProductCategory.ProductCategoryIDWHERE (DATEPART (Year, Sales.SalesOrderHeader.OrderDate) in (@ReportYear)) AND (DATEPART(Month, Sales.SalesOrderHeader.OrderDate)in( @ReportMonth)) AND (Sales.SalesOrderHeader.SalesPersonID = @EmpID)GROUP BY HumanResources.Employee.LoginID, DATEPART(Year, Sales.SalesOrderHeader.OrderDate), DATEPART(Month, Sales.SalesOrderHeader.OrderDate), DATENAME(Month, Sales.SalesOrderHeader.OrderDate), Production.ProductCategory.Name

▪ Create a third dataset ‘OrderYear’ to retriev the years. We will use

this for multi-valued parameters.

Select Distinct(Datepart(year,Sales.salesOrderHeader.Orderdate)) as OrderYear from Sales.SalesOrderHeader

▪ Select tabular layout.

▪ Drag and drop two text boxes into the report layout area.

▪ Set the DataSet property of table to EmpSalesMonth.

▪ Add a group header for ‘Employee’ – Value set to expression

“=Fields!Employee.Value”

11

Page 12: Reporting Services

Reporting Services

Exercise

F IELDS DATA ITEM PROPERTY

Order year and order

month

The two text Boxes Set value property for

the two text boxes as

follows:

Copy =Fields!

OrderMonth.Value into one

textbox

Copy

=Fields!OrderYear.Value

into second textbox

Group header for

employee

Drag and drop the field EmpSalesMont.Employee on the first column in Employee group header row. This will set Value in First column as “=Fields!Employee.Value ‘

ProdCat and sales

fields

Drag and drop the two

fields in Details row

Sales Drag and drop Sales

filed to group Footer

(last column)

12

Page 13: Reporting Services

Reporting Services

Exercise

▪ Use Report->Parameters menu to check that the following

parameters are present: ReportYear, ReportMonth, Year.

PARAMETERS PROPERTIES

Report Year Set DataType as integer

Available Values: From Query.

Select the third dataset

(‘OrderYear’) for ValueField.

ReportMonth Set Data Type as String.

Select Available Values: on-

Queries). Here, enter sets of

values such as:

Label:January

Index : 1

Label : February

Index 2 and so on til l December.

Select Default values: Non-queries

for month parameter and enter

“1” as default value.

EmpID Select Avaliable Values:From

13

Page 14: Reporting Services

Reporting Services

Exercise

Query

Set AvaliableValues->DataSet:

First DataSet

Set Value field and Label field as

EmployeeID.

▪ Run the report for output with the following parameters:-Year

=2004 Month = January EmpID = 283.

ReportYear - Multiparameter, ReportMonth and EmployeeID –

Single Parameter

▪ Create a list, Drag and Drop the table and textbox created initially

into the list.

▪ Right click the list and navigate as follows:

Properties->General->Dataset name-> EmpSalesMonth.

Properties->General->Edit Details group->General->Expression

=Fields!OrderYear.Value. Select the Check box for adding page

break after the group.

▪ Modify the Reportyear parameter in the following manner:

Report Year Check the Multi – Valued

checkbox

14

Page 15: Reporting Services

Reporting Services

Exercise

Available values

From query

Dataset – orderyear

Value field – orderyear

Label value – orderyear

▪ Run the report for Output with the following parameters:-Year =

2003, 2004 Month = January EmpID = 283.

ReportYear - Multiparameter, ReportMonth and EmployeeID –

MultiParameter

▪ Modify the list as follows add a group expression to existing group

expression:

Properties->General->Edit Details group->General->Expression

=Fields!OrderMonth.Value. Select the Check box for adding page

break after the group.

▪ Modify the Reportmonth parameter in the following manner:

Report month Check the Multi – Valued

checkbox

Default values

15

Page 16: Reporting Services

Reporting Services

Exercise

Non queried

Value: “1”,”2” and “3”

▪ Run the report for Output with the following parameters:-Year =

2003, 2004 Month = January, February and March. EmpID = 283.

EXERCISE 5: ORDER DETAILS

STEPS

▪ The following query gets the order details l ike quantity, price and

discount for a given salesordernumber. Create Orderdetail

dataset with this following query:

SELECT Sales.SalesOrderDetail. SalesOrderDetailID, Sales.SalesOrderDetail.OrderQty, Sales.SalesOrderDetail.UnitPrice, CASE WHEN sales.SalesOrderDetail.UnitPriceDiscount IS NULL THEN 0 ELSE sales.SalesOrderDetail.UnitPriceDiscount END AS UnitPriceDiscount, Sales.SalesOrderDetail.LineTotal, Sales.SalesOrderDetail.CarrierTrackingNumber, Sales.SalesOrderDetail.SalesOrderID, Production.Product.Name, Production.Product.ProductNumberFROM Sales.SalesOrderDetail INNER JOIN Production.Product ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID INNER JOIN Sales.SalesOrderHeader ON Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderIDWHERE (Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber)ORDER BY Sales.SalesOrderDetail. SalesOrderDetailID

16

Page 17: Reporting Services

Reporting Services

Exercise

▪ Create an another dataset called SalesOrder that gets the

shipping method, shipping address etc for a given

salesordernumber:

SELECT Sales.SalesOrderHeader.SalesOrderNumber, Sales.Store.Name AS SalesStore, Sales.SalesOrderHeader.OrderDate, HumanResources.Employee.LoginID AS SalesLoginID, HumanResources.Employee.Title AS SalesTitle, Sales.SalesOrderHeader.PurchaseOrderNumber, Purchasing.ShipMethod.Name AS ShipMethod, BillAddress.AddressLine1 AS BillAddress1, BillAddress.AddressLine2 AS BillAddress2, BillAddress.City AS BillCity, BillAddress.PostalCode AS BillPostalCode, BillStateProvince.Name AS BillStateProvince, ShipAddress.AddressLine1 AS ShipAddress1, ShipAddress.AddressLine2 AS ShipAddress2, ShipAddress.City AS ShipCity, ShipAddress.PostalCode AS ShipPostalCode, ShipStateProvince.Name AS ShipStateProvince, ShipCountryRegion.Name AS ShipCountryRegionFROM Sales.SalesOrderHeader LEFT OUTER JOIN Person.Address AS BillAddress INNER JOIN Person.StateProvince AS BillStateProvince ON BillAddress.StateProvinceID = BillStateProvince.StateProvinceID INNER JOIN Person.CountryRegion AS BillCountryRegion ON BillAddress.PostalCode = BillCountryRegion.CountryRegionCode ON Sales.SalesOrderHeader.BillToAddressID = BillAddress.AddressID LEFT OUTER JOIN Person.Address AS ShipAddress INNER JOIN Person.StateProvince AS ShipStateProvince ON ShipAddress.StateProvinceID = ShipStateProvince.StateProvinceID INNER JOIN Person.CountryRegion AS ShipCountryRegion ON ShipAddress.PostalCode = ShipCountryRegion.CountryRegionCode ON Sales.SalesOrderHeader.ShipToAddressID = ShipAddress.AddressID LEFT OUTER JOIN HumanResources.Employee ON Sales.SalesOrderHeader.SalesPersonID = HumanResources.Employee.EmployeeID LEFT OUTER JOIN Purchasing.ShipMethod ON Sales.SalesOrderHeader.ShipMethodID = Purchasing.ShipMethod.ShipMethodID LEFT OUTER JOIN Sales.Store ON Sales.SalesOrderHeader.CustomerID = Sales.Store.CustomerIDWHERE (Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber)

17

Page 18: Reporting Services

Reporting Services

Exercise

▪ Select tabular format and associate table with OrderDetail dataset

▪ Drag and drop a list above the table and associate it with

SalesOrder dataset

▪ Place text boxes in the list to retrieve values for:

SalesOrderNumber, Current Date (=Now() as value), Order Date

and Purchase Order no.

▪ Add a group with name as “Item” and GroupOn->Expression as

‘=Fields!Name.Value’

FORMAT

F IELD DATA ELEMENT GROUPING

PROPERTIES

Name, OrderQty,

UnitPrice,

LinePriceDiscount and

Line Total

(OrderDetail data set)

Drag and Drop name

to first column in Item

group header

Drag and drop the

other fields in Details

row

Add columns as you

proceed (Select right

most column and right

click ->Insert Column

18

Page 19: Reporting Services

Reporting Services

Exercise

to the right)

LineTotal Table footer (in the

last column)

While previewing the report, you need to provide the value for

SalesOrderNumber explicitly (e.g SO43860). This restriction will

be removed in the next exercise.

EXERCISE 6:

STEPS

▪ Use Report Generation Wizard with the inputs as provided below:

▪ Create a dataset with the following query

Which retrieves TerritoryName, SalesPersonId, Name,

Salesordernumber, TotalSales from SalesTerritory, SalesPerson,

Employee, SalesOrderHeader tables in the AdventureWorks

database):

SELECT Sales.SalesTerritory.Name, Sales.SalesPerson.SalesPersonID, HumanResources.Employee.LoginID, Sales.SalesOrderHeader.SalesOrderNumber, Sales.SalesOrderHeader.TotalDueFROM Sales.SalesTerritory INNER JOIN Sales.SalesPerson ON Sales.SalesTerritory.TerritoryID = Sales.SalesPerson.TerritoryID INNER JOIN HumanResources.Employee ON Sales.SalesPerson.SalesPersonID = HumanResources.Employee.EmployeeID INNER JOIN

19

Page 20: Reporting Services

Reporting Services

Exercise

Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID AND Sales.SalesPerson.SalesPersonID = Sales.SalesOrderHeader.SalesPersonIDGROUP BY Sales.SalesTerritory.Name, Sales.SalesPerson.SalesPersonID, HumanResources.Employee.LoginID, Sales.SalesOrderHeader.SalesOrderNumber, Sales.SalesOrderHeader.TotalDueORDER BY Sales.SalesTerritory.Name

▪ Report Type as Tabular

▪ Name, LoginId and SalesOrderNo fields as groups

▪ TotalDue as Detail field

▪ Once the report is created, for the SalesOrderNo. Text box, set the

Navigation->HyperLinkAction as “Jump To Report’. Specify the

report made in the previous exercise. Provide Parameter name and

value.( SalesOrderNumber, =Fields!SalesOrderNumber.Value)

▪ Set Font->Decoration for SalesOrderNo. As ‘Underline’

EXERCISE 7: PRODUCT CATALOG

STEPS

▪ Create a dataset with that lists the product category, subcategory,

name price and photo of products:

SELECT Production.Product.Name, Production.Product.ListPrice, Production.ProductPhoto.ThumbNailPhoto, Production.ProductCategory.Name AS Category,

20

Page 21: Reporting Services

Reporting Services

Exercise

Production.ProductSubcategory.Name AS SubCategoryFROM Production.Product INNER JOIN Production.ProductProductPhoto ON Production.Product.ProductID = Production.ProductProductPhoto.ProductID INNER JOIN Production.ProductPhoto ON Production.ProductProductPhoto.ProductPhotoID = Production.ProductPhoto.ProductPhotoID INNER JOIN Production.ProductSubcategory ON Production.Product.ProductSubcategoryID = Production.ProductSubcategory.ProductSubcategoryID INNER JOIN Production.ProductCategory ON Production.ProductCategory.ProductCategoryID = Production.ProductSubcategory.ProductCategoryIDGROUP BY Production.ProductCategory.Name, Production.ProductSubcategory.Name, Production.Product.Name, Production.Product.ListPrice, Production.ProductPhoto.ThumbNailPhoto

Drag and drop a list on the layout area and drag and drop a text

box on the list.

For the text box, set value property as =Fields!Category.Value

Set DataSet property for the list

In List properties, click the button ‘Edit DetailsGrouping’ , Create a

group on the list. Value is =Fields!Category.Value

Drag and drop another list within the first l ist. Place a text box

within this list.

For the text box in the inner list, set value property as =Fields!

SubCategory.Value

For the inner list, in List properties, click the button ‘Edit

DetailsGrouping’. Create a group on the list. Value is =Fields!

Category.Value

21

Page 22: Reporting Services

Reporting Services

Exercise

Drag and drop another list (third) within the second and place a

table in this list.

Create a group for the third list with value as =Fields!Name.Value

In the Details row in the table, Drag and drop the two fields: Name

and ListPirce.

Drag and drop an Image on the third column, This opens up the

Image Wizard. Provide the following details: ImageSource as

Database, Dataset as the one you have created already,

ThumbNailPhoto as the Image Field.

For all the three lists, in the properties, select “Navigation’” tab.

Set the Document Map Label property to be the same as the Group

Detail Value.

For the outermost list, check the checkbox titled “Insert a Page

Break before the list”.

EXERCISE 8: SALES VS. BUDGET REPORT

S t e p s :

▪ Create a dataset with the following query

Which retrieves Region wise, Category wise, Sub category wise

products’ sales and budget

SELECT ST.Name AS REGION, PC.Name AS CATEGORY, PS.Name AS SUBCATEGORY, SUM(SO.UnitPrice * SO.OrderQty) AS SALES, SUM(P.StandardCost * SO.OrderQty) AS BUDGET

22

Page 23: Reporting Services

Reporting Services

Exercise

FROM PRODUCTION.ProductSubCategory PS INNER JOIN SALES.SalesOrderHeader SH INNER JOIN SALES.SalesOrderDetail SO ON SH.SalesOrderID = SO.SalesOrderID INNER JOIN SALES.SalesTerritory ST ON SH.TerritoryID = ST.TerritoryID INNER JOIN PRODUCTION.Product P ON SO.ProductID = P.ProductID ON PS.ProductSubCategoryID = P.ProductSubCategoryID INNER JOIN PRODUCTION.ProductCategory PC ON PS.ProductCategoryID = PC.ProductCategoryIDGROUP BY PC.Name, PS.Name, ST.Name

▪ Place a list on the layout. Set its DataSet property. Create a

DetailsGroup with value as =Fields!REGION.Value

▪ Set the CheckBox ‘Insert a page break after this list”.

▪ Add a table within the list

▪ Add two groups for the table: Category and SubCategory

▪ Drag and drop Category field in the category group header (first

column)

▪ Drag and drop SubCategory field in the SubCategory group header

(second column)

▪ Place Sales and Budget fields in the Details area

▪ Within the list , drag and drop a Chart on the page before the

table. For the chart, set properties as follows:

o Data Pane: Set the DataSetName

23

Page 24: Reporting Services

Reporting Services

Exercise

o Add three CategoryGroups

:=Fields!SUBCATEGORY.Value,Fields!

CATEGORY.Value, Fields!REGION.Value

o Values: =Sum(Fields!SALES.Value) ,

o For the table properties check the checkbox of the

following properties: Insert Page break after the table,

Repeat header rows and row footers

24

Page 25: Reporting Services

Reporting Services

Exercise

II REPORT BUILDER

EXERCISE:

Building Report using Report Builder and Report Model

Steps

▪ Create a Project of type Report Model using Visual Studio 2005.

▪ Create a new Data Source using a new connection to Adventure

works.

▪ Create a Data Source View with the following tables:

o HumanResources.Employee

o Person. Contact

o Person.StateProvince

o Purchasing.VendorContact

o Sales.Individual

o Sales.SalesOrderHeader

o Sales.ContactCreditCard

o Sales.Customer

o Sales.Store

25

Page 26: Reporting Services

Reporting Services

Exercise

o Sales.CustomerAddress

o Sales.SalesTerritory

o Sales.SalesTerritoryHistory

o Sales.StoreContact

o Sales.SalesPerson

o Sales.SalesOrderDetail

▪ Create a new Report Model.

o Leave all defaults in the Report Model wizard.

o Run the Report Model wizard.

▪ Build the project and deploy the project.

▪ Open the webpage http://localhost/reports .

▪ Select the Models->Click on Report builder.

▪ Wait for the report builder to come up.

▪ In the Report builder do the following:

o New Report -> OK.

o Add Title as Sales Territory Report.

o Drop the ‘Sales Territory’ Entity from the Explorer’s list in

the report layout area labeled ‘drop column field’.

26

Page 27: Reporting Services

Reporting Services

Exercise

o In the explorer’s list select Sales People as territory ->

Sales Person->Contact.

o In the field’s list select ‘First Name’ & ‘Last Name’ and

drop it to the right of sales territory column in the report

layout.

o In the explorer’s list Select Sales Order Header.

o From the field’s list Drop the ‘#Sales Order Headers’ field

to the right of ‘Last name’ column in the report layout.

o From the field’s list drop the ‘Sum Total Due’ to the right

of ‘#SalesOrderHeader’ in the Report Layout.

o In the toolbar navigate the filter tool.

o In the explorer’s list select the Sales Order header Entity.

o From the field’s list expand ‘Order Date’. Drop the

following into the filter data area and Specify the Value in

the text box:

o OrderYear = 2002

o OrderMonth = 3

o Save the File as Sales Report.

o Run the report in the report builder and test the report.

o Switch to Design Report select row below ‘Sum Total due’

column header, right click -> format the and change the

following:

27

Page 28: Reporting Services

Reporting Services

Exercise

o Number-> defined formats ->$ 1,234.56.

o Run the Report.

III MANAGING REPORTS

EXERCISE:

G e t t i n g S t a r t e d

▪ Ensure that SQL Server agent service is running

▪ Create four shared folders in your system (This is required to test

data-driven and standard subscriptions using FileShareDelivery

Technique).

▪ Build and Deploy the project created earlier.

Standard subscription

▪ Go to the following URL of Report Manager:

http://localhost/reports

▪ Select the Matrix report (done in Exercise 1) thru the home page

of the Report Manager

In Properties pane ->DataSources:

28

Page 29: Reporting Services

Reporting Services

Exercise

Select the radio button “A Custom Data Source”

Connection Type: Microsoft SQL Server

connection string: Datasource=

localhost;init ialcatalog=adventureworks

Connection Using : credentials stored securely in the report

server

Specify Username & password1 (Local computer user).

Select “Use as Windows Credentials when connecting to the data

source”

In Subscriptions pane:

Select New subscription

o Select Report Delivery Option ->Report Server Fi leshare.

o Give appropriate fi lename.

o Select the path of one of the shared folders you created (Path

to be given in UNC eg:- \\computername\Drive$\sharename).

o Select the render format of the report.

o Give credentials to access the fi le share (user ID and

Password).

o Select Overwrite f i le share option.

o Select the schedule to run the report

o Schedule: hour, Give the appropriate time to run the report

and give appropriate start t ime.

o After the start t ime, View the shared directory and check that

the report has been dropped.

29

Page 30: Reporting Services

Reporting Services

Exercise

Data Driven subscription

▪ Create a Subscriberdetail table in adventureworks database as

follows:

i f exists (select * from dbo.sysobjects where id = object_id(N'[dbo].

[subscriberdetai l] ' ) and OBJECTPROPERTY(id, N' IsUserTable') = 1)

drop table [dbo].[subscriberdetai l]

GO

CREATE TABLE [dbo].[subscriberdetai l] (

[Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS

NOT NULL ,

[Fi le_Share] [varchar] (165) COLLATE

SQL_Latin1_General_CP1_CI_AS NOT NULL ,

[EmployeeID] [varchar] (50) COLLATE

SQL_Latin1_General_CP1_CI_AS NULL ,

[Media_format] [varchar] (50) COLLATE

SQL_Latin1_General_CP1_CI_AS NULL

) ON [PRIMARY]

GO

▪ Insert Rows into the above table

30

Page 31: Reporting Services

Reporting Services

Exercise

Insert into [dbo].[subscriberdetai l] values( ‘ localhost\user’ , <Fi le

share 1>, 10, ‘CSV’)

Insert into [dbo].[subscriberdetai l] values( ‘Arun’, <Fi le share 2>,

10, ‘Excel’)

Insert into [dbo].[subscriberdetai l] values( ‘Meena’, <Fi le share 3>,

10, ‘HTML 4.0’)

▪ Go to the following URL of Report Manager:

http://localhost/reports

▪ Select the Matrix report thru the home page of the Report Manager

In Subscription pane, Select New Data driven subscription

o Delivery Option

Description: Name of the subscription.

Specify how recipients are notif ied: Report Server Fi le

share

o Connect to the subscriberdetail table

connection string: Datasource localhost;

init ialcatalog=adventureworks

Credentials (localhost\user, password)

Use Windows Credentials

o Query the subscriberdetail table as fol lows and validate

query:

31

Page 32: Reporting Services

Reporting Services

Exercise

Select * from subscriberdetai l

o Choose the delivery extension settings

Filename: appropriate

File extension: true

Path: get value from database->file_share

Render format: get value from database->Media_format

Username: (localhost\user, password)

WriteMode: Overwrite

o Select the schedule to run the report

o Schedule: hour, Give the appropriate time to run the report

and give appropriate start t ime.

o After the start t ime check the fi le shares for each subscriber.

IV URL ACCESS

EXERCISE:

SCENARIOS

▪ Use Command Parameter – ListChildren, Render

▪ Render by specifying Format property

32

Page 33: Reporting Services

Reporting Services

Exercise

▪ Pass a parameter and render a report that is parameterized

V PROGRAMMATIC ACCESS TO REPORTING WEB

SERVICE

EXERCISE:

SCENARIOS

▪ Create a WinForms application and add reference to Report Server

Web Services

(http://server/reportserver/ReportService2005.asmx?wsdl,

http://server/reportserver/ReportExecution2005.asmx?wsdl

▪ Management Related

o List al l items in a given path (ListChildren method)

o List al l properties of a given item – folder or report item

(GetProperties method)

o Create a new Folder (CreateFolder method)

o Create a Subscription (CreateSubscription method)

▪ Executing a report

33

Page 34: Reporting Services

Reporting Services

Exercise

localhost1.ReportExecutionService rs = new localhost1.ReportExecutionService(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; rs.Url = "http://localhost/reportserver/ReportExecution2005.asmx"; // Render arguments byte[] result = null; string reportPath = "/<Your Report Project>/Report2"; string format = "MHTML"; string historyID = null; string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; localhost1.DataSourceCredentials[] credentials = null; string showHideToggle = null; string encoding; string mimeType; localhost1.Warning[] warnings = null; localhost1.ParameterValue[] reportHistoryParameters = null; string[] streamIDs = null;

ExecutionInfo execInfo = new ExecutionInfo(); ExecutionHeader execHeader = new ExecutionHeader();

rs.ExecutionHeaderValue = execHeader;

execInfo = rs.LoadReport(reportPath, historyID);

String SessionId = rs.ExecutionHeaderValue.ExecutionID;

MessageBox.Show("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);

try { result = rs.Render(format, devInfo, out encoding, out mimeType, out warnings, out streamIDs);

execInfo = rs.GetExecutionInfo();

MessageBox.Show("Execution date and time: {0}", execInfo.ExecutionDateTime.ToString());

} catch (SoapException ex) { MessageBox.Show(ex.Detail.OuterXml);

34

Page 35: Reporting Services

Reporting Services

Exercise

} // Write the contents of the report to an MHTML file. try { FileStream stream = File.Create("report.mht", result.Length); MessageBox.Show("File created."); stream.Write(result, 0, result.Length); MessageBox.Show("Result written to the file."); stream.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); }

}

VI GENERATING RDL USING THE .NET FRAMEWORK

Steps

▪ Create a Visual C# Console application project.

▪ The Layout of the report that is generated by the RDL file is as

follows:

CountryName Province

------ - - - - - - - - - -

- - - - - - - -

35

Page 36: Reporting Services

Reporting Services

Exercise

- - - - - - - -

▪ Create a Connection string for Adventureworks database as

follows:

“data source=localhost; init ial catalog=AdventureWorks; integrated

security=SSPI”

▪ Use the SQLCommand to execute the following query:

"SELECT Person.CountryRegion.Name AS CountryName,

Person.StateProvince.Name AS StateProvince " +

"FROM Person.StateProvince " +

" INNER JOIN Person.CountryRegion ON

Person.StateProvince.CountryRegionCode =

Person.CountryRegion.CountryRegionCode " +

"ORDER BY Person.CountryRegion.Name";

command.CommandText = m_commandText;

▪ Execute using datareader.

▪ Add fields from data reader to an array list.

▪ Use the XMLTextWriter to generate the following XML File:

36

Page 37: Reporting Services

Reporting Services

Exercise

<?xml version="1.0" encoding="utf-8"?>

<Report

xmlns="http:/ /schemas.microsoft.com/sqlserver/report ing/2005/01/r

eportdefinit ion">

<Width>6in</Width>

<DataSources>

<DataSource Name="DataSource1">

<ConnectionProperties>

<DataProvider>SQL</DataProvider>

<ConnectString>data source=localhost; init ial

catalog=AdventureWorks; integrated security=SSPI</ConnectString>

<IntegratedSecurity>true</IntegratedSecurity>

</ConnectionProperties>

</DataSource>

</DataSources>

<DataSets>

<DataSet Name="DataSet1">

<Query>

<DataSourceName>DataSource1</DataSourceName>

37

Page 38: Reporting Services

Reporting Services

Exercise

<CommandType>Text</CommandType>

<CommandText>SELECT Person.CountryRegion.Name AS

CountryName, Person.StateProvince.Name AS StateProvince FROM

Person.StateProvince INNER JOIN Person.CountryRegion ON

Person.StateProvince.CountryRegionCode =

Person.CountryRegion.CountryRegionCode ORDER BY

Person.CountryRegion.Name</CommandText>

<Timeout>30</Timeout>

</Query>

<Fields>

<Field Name="CountryName">

<DataField>CountryName</DataField>

</Field>

<Field Name="StateProvince">

<DataField>StateProvince</DataField>

</Field>

</Fields>

</DataSet>

</DataSets>

<Body>

38

Page 39: Reporting Services

Reporting Services

Exercise

<Height>5in</Height>

<ReportItems>

<Table Name="Table1">

<DataSetName>DataSet1</DataSetName>

<Top>.5in</Top>

<Left>.5in</Left>

<Height>.5in</Height>

<Width>3in</Width>

<TableColumns>

<TableColumn>

<Width>1.5in</Width>

</TableColumn>

<TableColumn>

<Width>1.5in</Width>

</TableColumn>

</TableColumns>

<Header>

<TableRows>

39

Page 40: Reporting Services

Reporting Services

Exercise

<TableRow>

<Height>.25in</Height>

<TableCel ls>

<TableCel l>

<ReportItems>

<Textbox Name="HeaderCountryName">

<Style>

<TextDecoration>Underl ine</TextDecoration>

</Style>

<Top>0in</Top>

<Left>0in</Left>

<Height>.5in</Height>

<Width>1.5in</Width>

<Value>CountryName</Value>

</Textbox>

</ReportItems>

</TableCel l>

<TableCel l>

40

Page 41: Reporting Services

Reporting Services

Exercise

<ReportItems>

<Textbox Name="HeaderStateProvince">

<Style>

<TextDecoration>Underl ine</TextDecoration>

</Style>

<Top>0in</Top>

<Left>0in</Left>

<Height>.5in</Height>

<Width>1.5in</Width>

<Value>StateProvince</Value>

</Textbox>

</ReportItems>

</TableCel l>

</TableCel ls>

</TableRow>

</TableRows>

</Header>

<Detai ls>

41

Page 42: Reporting Services

Reporting Services

Exercise

<TableRows>

<TableRow>

<Height>.25in</Height>

<TableCel ls>

<TableCel l>

<ReportItems>

<Textbox Name="CountryName">

<Style />

<Top>0in</Top>

<Left>0in</Left>

<Height>.5in</Height>

<Width>1.5in</Width>

<Value>=Fields!CountryName.Value</Value>

<HideDuplicates>DataSet1</HideDuplicates>

</Textbox>

</ReportItems>

</TableCel l>

<TableCel l>

42

Page 43: Reporting Services

Reporting Services

Exercise

<ReportItems>

<Textbox Name="StateProvince">

<Style />

<Top>0in</Top>

<Left>0in</Left>

<Height>.5in</Height>

<Width>1.5in</Width>

<Value>=Fields!StateProvince.Value</Value>

<HideDuplicates>DataSet1</HideDuplicates>

</Textbox>

</ReportItems>

</TableCel l>

</TableCel ls>

</TableRow>

</TableRows>

</Detai ls>

</Table>

</ReportItems>

43

Page 44: Reporting Services

Reporting Services

Exercise

</Body>

</Report>

▪ Build the project.

▪ View the report generated by the RDL file in the bin directory.

*** End of Document ***

44


Recommended