Sunteți pe pagina 1din 41

Reporting Services

Exercise

I DESIGNING REPORTS EXERCISE1:


STEPS:

Create a data set with the Query below

W hi c h re trie ve s Produc t C ate gory, sub c ate gory, Ye ar, Q uarte r, Month w i se sal e s from ProductSubCategory, SalesOrderHeader, SalesTerritory, SalesOrderDetail tabl e s i n Adve ntu re W ork s databa se for pe ri od of 20 02 and 20 03 :

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 PRODUCTION.ProductCategory PC ON PS.ProductCategoryID = PC.ProductCategoryID WHERE (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 Add ProdCat, SubCat fields to row group in the Matrix

Reporting Services

Exercise

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 FIELD INITIAL PROPERTY VI SI BI LI T Y W H E T H E R


BY CAB BE TOGGED

ANOTHER AND IF

PRODUCT
YES, THE

ITEM

REPORT ITEM
ProductCat Subcat OrderYear OrderQtr OrderMonth Country Visible Hidden Visible Hidden Hidden Hidden ProductCat OrderYear OrderQtr OrderMonth

SO RT I NG

SORT the OrderQtr by Ascending.

Reporting Services

Exercise

ADD

BACKGROUND

PROPERTY
Prerequisite task

SUB
Drag

PROPERTY

VALUE
drop

and

Image item from Toolbox Background Image Source Value Embedded Chose image Embedded using the

image Wizard Note: image placed report Background Source and Value Delete on the the

control layout,

after you set the

FORMAT

FORMAT Add Border Style & Color to entire matrix Assign background Color for each text box in the matrix

VALUE Solid & Black Yellow

Reporting Services

Exercise

Assign Border for each text box in the matrix Drag and drop a text box on top of the matrix report ProductCat

Solid

Name of the Report Text Align: Left

SubCat

Text Align : Right

OrderYear, OrderQtr, OrderMonth, Country, Sales

Text Align: Center

Preview the Report Sort : quarter, month and country Remove OrderQtr from Matrix Remove OrderMonth Remove the image

EXERCISE 2:
STEPS:

Create a Employee dataset with the following query:

Reporting Services

Exercise

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 ON E.ContactID = C.ContactID Where D.DepartmentID=1 Order By c.lastname

Create a Department dataset with the following query:

SELECT 0 AS DepartmentID, 'All' AS Name UNION SELECT DepartmentID, Name FROM HumanResources.Department ORDER BY Name

Add a Table in the layout view placing the following fields from the first data set in Detail Area:

F i rstN ame L astN ame Ti tl e

Using the menu option Report ->ReportParameters, create a report parameter with the following properties set:

N ame : De partme n t Data Type : Stri ng Promp t: De parme nt Al l ow nul l val ue , Al l ow bl ank val ue : Fal se F or Avai l abl e val ue s, se le c t F rom que ry. Datase t: De partme nts

Reporting Services

Exercise

o o

Val ue fi e l d: De partme ntI D L abe l fie l d: N ame.

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 " & "ON E.ContactID = C.ContactID " & Iif(Parameters!Department.Value Parameters!Department.Value) & "ORDER BY C.LastName" = 0, "", "WHERE D.DepartmentID = " &

Preview the report the query will use the report parameter.

EXERCISE 3:
STEPS:

Create a dataset with the following query:

W hi c h

re tri e ve s

produc t

wi se ,

qua nti ty

sol d

from

product,

SalesOrderDetail, and SalesOrderheader tables SELECT Production.Product.Name, SUM(Sales.SalesOrderDetail.OrderQty) AS [ Quantity Sold ], DATEPART(yy, Sales.SalesOrderHeader.OrderDate) AS Year FROM Production.Product INNER JOIN

Reporting Services

Exercise

Sales.SalesOrderDetail ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID INNER JOIN Sales.SalesOrderHeader ON Sales.SalesOrderHeader.SalesOrderID = Sales.SalesOrderDetail.SalesOrderID GROUP 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 Add Itemname field to grouping table properties.

GROUPING FIELD
ItemName (Header)

PROPERTY
Select the following: Include group header Include group footer Page Break at end Repeat group header Repeat group footer

Year

of

Sale Select the following: Include group header Include group footer

(header)

Reporting Services

Exercise

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
FORMAT Add Border & Color to entire Table Text Alignment in the Table Data Sorting Assign color & make the font bold for Table Group Header Center Year Orange VALUE Solid & Black

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.

Reporting Services

Exercise

Add conditional format Set Expression Quantity Sold Textbox using expression
ID_Quantity_Sold_.Value < 300, "Red", "Black")

in Font Property of like this:


=iif(Fields!

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 Employee FROM HumanResources.Employee INNER JOIN Sales.SalesPerson ON HumanResources.Employee.EmployeeID = Sales.SalesPerson.SalesPersonID ORDER 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 Sales FROM Sales.SalesOrderHeader INNER JOIN

Reporting Services

Exercise

Sales.SalesOrderDetail ON Sales.SalesOrderHeader.SalesOrderID = Sales.SalesOrderDetail.SalesOrderID INNER JOIN 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.ProductCategoryID WHERE (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

10

Reporting Services

Exercise

FIELDS
Order year and

DATA ITEM
The two text Boxes

PROPERTY
Set value property for the two text boxes as follows: Copy
one textbox =Fields! into

order month

OrderMonth.Value

Copy
=Fields!OrderYear.Value into second textbox

Group header for employee

Drag and drop the field EmpSalesMont.Employ ee 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)

11

Reporting Services

Exercise

Use

Report->Parameters

menu

to

check

that

the

following

parameters are present: ReportYear, ReportMonth, Year.

PARAMETERS
Report Year

PROPERTIES
Set DataType as integer Available Values: From Query. Select the third dataset (OrderYear) for ValueField.

ReportMonth

Set Data Type as String. Select Available Here, Values: on-

Queries).

enter sets of

values such as: Label:January Index : 1 Label : February Index 2 and so on till December. Select queries Default for values: Non-

month

parameter

and enter 1 as default value. EmpID Select Query Set AvaliableValues->DataSet: Avaliable Values:From

First DataSet

12

Reporting Services

Exercise

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:
Prope rti e s- > Ge ne ral -> Datase t name -> EmpSal e sMont h. Prope rti e s- > Ge ne ral -> Edi t bre ak afte r the group. De tai l s group- > Ge ne ral - >Expre ssi on

= Fi e l ds!O rde rYe ar. Val ue . Se le c t the C he c k box for addi ng page

Modify the Reportyear parameter in the following manner: Report Year Check the Multi Valued

checkbox Available values From query Dataset orderyear Value field orderyear Label value orderyear

13

Reporting Services

Exercise

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:
Prope rti e s- > Ge ne ral -> Edi t bre ak afte r the group. De tai l s group- > Ge ne ral - >Expre ssi on

= Fi e l ds!O rde rMonth. V al ue . Se le c t the C he c k box for addi ng page

Modify the Reportmonth parameter in the following manner: Report month Check the Multi Valued

checkbox Default values 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.

14

Reporting Services

Exercise

EXERCISE 5: ORDER DETAILS


STEPS

The following query gets the order details like 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.ProductNumber FROM Sales.SalesOrderDetail INNER JOIN Production.Product ON Sales.SalesOrderDetail.ProductID = Production.Product.ProductID INNER JOIN Sales.SalesOrderHeader ON Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderID WHERE (Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber) ORDER BY Sales.SalesOrderDetail. SalesOrderDetailID

Create shipping

an

another method,

dataset

called

SalesOrder etc

that for

gets a

the

shipping

address

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 ShipCountryRegion

15

Reporting Services

Exercise

FROM

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.CustomerID WHERE (Sales.SalesOrderHeader.SalesOrderNumber = @SalesOrderNumber)

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), and Purchase Order no.

Order Date

Add a group with name as Item and GroupOn->Expression as =Fields!Name.Value

FORMAT

16

Reporting Services

Exercise

FIELD
Name, OrderQty, UnitPrice, LinePriceDiscount and Line Total (OrderDetail data set)

DATA ELEMENT
Drag name column and to in Drop first Item

GROUPING PROPERTIES

group header Drag and drop the other fields in Details row Add you (Select column click Column right) columns right and to as most right the

proceed

->Insert

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

17

Reporting Services

Exercise

Use Report Generation Wizard with the inputs as provided below: Create a dataset with the following query

W hi c h Employee,

re tri e ve s

Te rri toryN ame , Total Sal e s from in tabl e s

Sal e sPe rsonI d, SalesTerritory, the

N ame ,

Sal e sorde rnum be r, data base ):

SalesPerson,

SalesOrderHeader

Adve nture W ork s

SELECT Sales.SalesTerritory.Name, Sales.SalesPerson.SalesPersonID, HumanResources.Employee.LoginID, Sales.SalesOrderHeader.SalesOrderNumber, Sales.SalesOrderHeader.TotalDue FROM 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 Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID AND Sales.SalesPerson.SalesPersonID = Sales.SalesOrderHeader.SalesPersonID GROUP BY Sales.SalesTerritory.Name, Sales.SalesPerson.SalesPersonID, HumanResources.Employee.LoginID, Sales.SalesOrderHeader.SalesOrderNumber, Sales.SalesOrderHeader.TotalDue ORDER 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)

18

Reporting Services

Exercise

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, Production.ProductSubcategory.Name AS SubCategory FROM 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.ProductCategoryID GROUP 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

19

Reporting Services

Exercise

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 list. 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 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 Dataset as the following details: ImageSource the one you have created as Database, 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.

20

Reporting Services

Exercise

EXERCISE 8: SALES VS. BUDGET REPORT


Steps:

Create a dataset with the following query

W hi c h re tri e ve s Re gi on wi se , C ate gory wi se , Sub c ate gory w i se produc ts sale s and bud ge t

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 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.ProductCategoryID GROUP 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)

21

Reporting Services

Exercise

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 o Data Pane: Set the DataSetName Add three CategoryGroups :=Fields!SUBCATEGORY.Value,Fields! CATEGORY.Value, Fields!REGION.Value o o Values: =Sum(Fields!SALES.Value) , For the table properties check the checkbox of the

following properties: Insert Page break after the table, Repeat header rows and row footers

22

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 o o o o o o o o o HumanResources.Employee Person. Contact Person.StateProvince Purchasing.VendorContact Sales.Individual Sales.SalesOrderHeader Sales.ContactCreditCard Sales.Customer Sales.Store Sales.CustomerAddress

23

Reporting Services

Exercise

o o o o o

Sales.SalesTerritory Sales.SalesTerritoryHistory Sales.StoreContact Sales.SalesPerson Sales.SalesOrderDetail

Create a new Report Model. o o Leave all defaults in the Report Model wizard. 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 o o New Report -> OK. Add Title as Sales Territory Report. Drop the Sales Territory Entity from the Explorers list in the report layout area labeled drop column field. o In the explorers list select Sales People as territory -> Sales Person->Contact.

24

Reporting Services

Exercise

In the fields list select First Name & Last Name and drop it to the right of sales territory column in the report layout.

o o

In the explorers list Select Sales Order Header. From the fields list Drop the #Sales Order Headers field to the right of Last name column in the report layout.

From the fields list drop the Sum Total Due to the right of #SalesOrderHeader in the Report Layout.

o o o

In the toolbar navigate the filter tool. In the explorers list select the Sales Order header Entity. From the fields list expand Order Date. Drop the

following into the filter data area and Specify the Value in the text box: o o o o o OrderYear = 2002 OrderMonth = 3 Save the File as Sales Report. Run the report in the report builder and test the report. Switch to Design Report select row below Sum Total due column header, right click -> format the and change the following: o o Number-> defined formats ->$ 1,234.56. Run the Report.

25

Reporting Services

Exercise

III MANAGING REPORTS EXERCISE:


Getting Started

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:

ht t p :/ / lo calho s t/ re p o rts

Select the Matrix report (done in Exercise 1) thru the home page of the Report Manager

I n Prope rti e s pane -> DataSo urc e s: Se l e c t the radi o button A C ustom Data Sourc e C onne c ti on Type : Mi c rosoft SQ L Se rve r c onne c ti on stri ng: Datasourc e = l oc al host; i ni ti al c atal og= a dve nt ure w ork s

C onne c ti on Usi ng : c re de nti al s store d se c ure l y i n the re port se rve r

26

Reporting Services

Exercise

Spe c i fy Use rname & passw ord1 (L oc al c ompute r use r). Se l e c t Use as W i ndow s C re de nti al s w he n c onne c ti ng to the data sourc e

I n Subsc ri p ti ons pane : Se l e c t Ne w subsc ri p ti on o o o Se l e c t Re port De li ve ry O pti on -> Re port Se rve r F il e share . Gi ve approp ri ate fi l e name . Se l e c t the path of one of the share d fol de rs you c re ate d (Path to be gi ve n i n UN C e g: - \ \ c ompute rna me \ Dri ve$ \ share name ). o o Se l e c t the re nde r format of the re port. Gi ve c re de nti al s to ac c e ss the fi l e share (use r I D and Passw ord). o o o Se l e c t Ove rw ri te fi le share opti on. Se l e c t the sc he dul e to run the re port Sc he dul e : hour, Gi ve the appro pri ate ti me to run the re port and gi ve appropri a te start ti me . o Afte r the start ti me , Vi e w the share d di re c tory and c he c k that the re port has be e n droppe d.

Data Driven subscription

Create a Subscriberdetail table in adventureworks database as follows:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[subscriberdetail]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

27

Reporting Services

Exercise

drop table [dbo].[subscriberdetail] GO CREATE TABLE [dbo].[subscriberdetail] ( [Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [File_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

Insert into [dbo].[subscriberdetail] values( localhost\user, <File share 1>, 10, CSV) Insert into [dbo].[subscriberdetail] values( Arun, <File share 2>, 10, Excel) Insert into [dbo].[subscriberdetail] values( Meena, <File share 3>, 10, HTML 4.0)

Go to the following URL of Report Manager:

28

Reporting Services

Exercise

ht t p :/ / lo calho s t/ re p o rts

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

I n Subsc ri p ti on pane , Se l e c t Ne w Data dri ve n subsc ri pti o n o De li ve ry O pti on De sc ri pti on: N ame of the subsc ri pti on. Spe c i fy how re c i pi e nts are noti fi e d: Re port Se rve r F il e share o C onne c t to the subsc ri be rde tai l tabl e c onne c ti on stri ng: Datasourc e l oc al host; i ni ti al c atal og= ad ve nture w ork s o C re de nti al s (l oc al host\ use r, passw ord) Use Wi ndow s C re de nti al s

Q ue ry the subsc ri be rde tai l tabl e as fol l ow s and val i date que ry:

Select * from subscriberdetail


o C hoose the de l i ve ry e xte nsi on se tti ngs o F il e name : appropri a te F il e exte nsi on: true Path: ge t val ue from data base - > fil e _share Re nde r format: ge t val ue from database - > Me di a_format Use rname : (l oc al host\ use r, passw ord) W ri te Mode : O ve rw ri te

Se l e c t the sc he dul e to run the re port

29

Reporting Services

Exercise

Sc he dul e : hour, Gi ve the appro pri ate ti me to run the re port and gi ve appropri a te start ti me .

Afte r the start ti me c he c k the fi le share s for e ac h subsc ri be r.

IV URL ACCESS EXERCISE:

SC E NA RI OS

Use Command Parameter ListChildren, Render Render by specifying Format property Pass a parameter and render a report that is parameterized

PROGRAMMATIC

ACCESS

TO

REPORTING

WEB

SERVICE EXERCISE:

SC E NA RI OS

Create a WinForms application and add reference to Report Server Web Services

30

Reporting Services

Exercise

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

Management Related
o o L i st al l i te ms i n a gi ve n path (L i stC hi l dre n me thod) L i st al l prope rti e s of a gi ve n i te m fol de r or re port i te m (Ge tPrope rti e s me thod) o o C re ate a ne w F ol de r (C re ateF ol de r me thod) C re ate a Subsc ri pti on (C re ate Subsc ri pti on me thod)

Executing a report

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);

31

Reporting Services

Exercise

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); } // 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

32

Reporting Services

Exercise

Create a Visual C# Console application project. The Layout of the report that is generated by the RDL file is as follows:

CountryName --------

Province ----------------------

Create follows:

Connection

string

for

Adventureworks

database

as

data source=localhost;initial 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;

33

Reporting Services

Exercise

Execute using datareader. Add fields from data reader to an array list. Use the XMLTextWriter to generate the following XML File:

< ? x m l ve r s i o n = " 1 . 0 " e n c o d i n g = " u t f - 8 " ? > <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01 /reportdefinition"> < W i d t h > 6i n < / W i d t h > <DataSources> <DataSource Name="DataSource1"> <ConnectionProperties> <DataProvider>SQL</DataProvider> <ConnectString>data source=localhost;initial catalog=AdventureWorks;integrated security=SSPI</ConnectString> <IntegratedSecurity>true</IntegratedSecurity> </ConnectionProperties> </DataSource> </DataSources>

34

Reporting Services

Exercise

<DataSets> <DataSet Name="DataSet1"> <Query> <DataSourceName>DataSource1</DataSourceName> <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>

35

Reporting Services

Exercise

</DataSet> </DataSets> <Body> <Height>5in</Height> <ReportItems> <Table Name="Table1"> <DataSetName>DataSet1</DataSetName> <Top>.5in</Top> <Left>.5in</Left> <Height>.5in</Height> < W i d t h > 3i n < / W i d t h > <TableColumns> <TableColumn> < W i d t h > 1 . 5i n < / W i d t h > </TableColumn> <TableColumn> < W i d t h > 1 . 5i n < / W i d t h > </TableColumn> </TableColumns> <Header>

36

Reporting Services

Exercise

<TableRows> <TableRow> <Height>.25in</Height> <TableCells> <TableCell> <ReportItems> <Textbox Name="HeaderCountryName"> <Style> <TextDecoration>Underline</TextDecoration> </Style> <Top>0in</Top> <Left>0in</Left> <Height>.5in</Height> <Width>1.5in</Width> <Value>CountryName</Value> </Textbox> </ReportItems> </TableCell> <TableCell> <ReportItems>

37

Reporting Services

Exercise

<Textbox Name="HeaderStateProvince"> <Style> <TextDecoration>Underline</TextDecoration> </Style> <Top>0in</Top> <Left>0in</Left> <Height>.5in</Height> <Width>1.5in</Width> <Value>StateProvince</Value> </Textbox> </ReportItems> </TableCell> </TableCells> </TableRow> </TableRows> </Header> <Details> <TableRows> <TableRow> <Height>.25in</Height>

38

Reporting Services

Exercise

<TableCells> <TableCell> <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> </TableCell> <TableCell> <ReportItems> <Textbox Name="StateProvince"> <Style /> <Top>0in</Top> <Left>0in</Left>

39

Reporting Services

Exercise

<Height>.5in</Height> <Width>1.5in</Width> <Value>=Fields!StateProvince.Value</Value> <HideDuplicates>DataSet1</HideDuplicates> </Textbox> </ReportItems> </TableCell> </TableCells> </TableRow> </TableRows> </Details> </Table> </ReportItems> </Body> </Report>

Build the project. View the report generated by the RDL file in the bin directory.

40

Reporting Services

Exercise

*** End of Document ***

41

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