Date post: | 26-Oct-2014 |
Category: |
Documents |
Upload: | santhosh1212 |
View: | 380 times |
Download: | 9 times |
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
EXERCISES ON REPORTING SERVICES
PRE-REQUISITES
▪ Open Business Intelligence Development Studio and create a
project by selecting “Report Server Server”.
▪ Create a Data Source with AdventureWorks Database and
Windows NT Authentication
▪ In the Project properties set the target path as
http://localhost/reportserver
I DESIGNING REPORTS
EXERCISE1:
LEARNING POINTS:
Embedded Image
Matrix Report
Dril ldown
Grouping and Sorting
Use of Text Box
Toggle Grouped items on the report
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:
1
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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 to Design Layout
▪ 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 CAN BE
TOGGED BY ANOTHER
PRODUCT ITEM AND IF
YES, THE REPORT
2
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
ITEM
ProductCat Visible -
Subcat Hidden ProductCat
OrderYear Visible -
OrderQtr Hidden OrderYear
OrderMonth Hidden OrderQtr
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
3
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
placed on the
report layout,
after you set the
Background
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
ADDITIONAL SCENARIOS TO TEST:
4
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Sort : quarter, month and country
▪ Remove OrderQtr from Matrix
▪ Remove OrderMonth
▪ Remove the image
EXERCISE 2:
LEARNING POINTS:
Creating Dynamic Queries
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
▪ Add a Table in the layout view placing the following fields from the
first data set in Detail Area:
FirstName
5
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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.
Dataset: Departments
Value field: DepartmentID
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 " &
"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:
6
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
LEARNING POINTS:
Tabular report
Grouping
Sorting
Using Page Header & Page Footer
Embedding Image
Using page Numbers
Interactive Sorting
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
▪ Add Itemname field to grouping table properties.
GROUPING
F IELD PROPERTY
7
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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
FORMAT VALUE
Add Border & Color to entire
Table
Solid & Black
Text Alignment in the Table Center
Data Sorting Year
8
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
Assign color & make the font bold
for Table Group Header
Orange
▪ To add Page Numbers in page footers : Navigate 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 the column heading for the year column. Right-click for
Properties and select Interactive Sort. Select Add an interactive
sort action to this text box. Specify the sort expressions as
=Fields!Year.Value.
▪ Preview the report. Check that the effect of GroupHeader is not visible. Check the effect of
Interactive sort.
ADDITIONAL:
▪ 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")
▪ 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.
9
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
EXERCISE 4:
LEARNING POINTS:
Tabular report
Using Multiple data sets
Using Parameters
Using single and multi-valued parameters
Scenario 1 : Three parameters, all single-valued
▪ Create a 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 another 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 Sales.SalesPerson ON Sales.SalesOrderHeader.SalesPersonID = Sales.SalesPerson.SalesPersonID INNER JOIN
10
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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 retrieve the years. We will
use this for multi-valued parameters.
Select Distinct(Datepart(year,Sales.salesOrderHeader.Orderdate)) as OrderYear from Sales.SalesOrderHeader
▪ Drag and drop the table to the design layout.
▪ Right click on the table select tablix properties
Dataset name = EmpSales
▪ Go to parameters select reportYear right click on it select
parameter properties
Click on Available values choose get values from a query
Set dataset name = OrderYear
ValueField = OrderYear
labelField = OrderYear
Click OK
11
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Again Go to parameters select EmpID right click on it select
parameters properties
Click on Available values choose get values from a query
Set dataset name = SalesEmployee
ValueField = EmpID
LabelField = EmpID
Click ok
▪ Again Go to parameters select ReportMonth right click on it
select parameters properties
Click on Available values choose specify values from a query
Add 12 labels and name them from Jan to Dec, values from 1 to
12
Click Ok
12
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
Click OK
▪ Run the report for output with the following parameters:-Year
=2004 Month = January EmpID = 283.
Scenario 2 : Three parameters, one is multi-valued
▪ Remove the Table from above Report
▪ Drag and Drop a list to the design layout
▪ Place table into this list.
▪ Add data to the table from EmpMONTH dataset
13
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Select List and Delete Details from RowGroup (from down left panel
of the window)
▪ Select List Right Click Add Group Row Group Parent
Group
▪ Group by = Order Year
▪ Click OK
▪ Go to parameters Right Click on ‘ReportYear’ Properties
Check Allow multiple vales
▪ Click OK
Run the report. Verify that the entire list of unique year values is
displayed. Run the report and verify output with the following
parameters: Year = 2003, 2004 Month = January EmpID = 283.
Scenario 3 : Three parameters, two are multi-valued
▪ Go to design layout of Above Report
▪ Select list select order Year right click add group child
group group by = OrderMonth
▪ Click OK
▪ Go to parameters right click ReportMonth parameters
properties check allow multiple values
▪ Click default values from left panel
14
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Choose specify values add values
Value = 1
Value = 2
Click OK
▪ Run the report for Output with the following parameters:-Year =
2003, 2004 Month = January, February and March. EmpID = 283.
EXERCISE 5: ORDER DETAILS
LEARNING POINT:
Table report
List
STEPS
▪ The following query gets the order details l ike quantity, price and
discount for a given salesordernumber. Create OrderDetails
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
15
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ 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)
▪ Drag and drop a table on design layout
16
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Select table and associate table with OrderDetails dataset
▪ Drag and drop a list on 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
to the right)
LineTotal Table footer (in the
last column)
17
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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:
LEARNING POINTS:
Tabular report
Grouping
Using Page Header & Page Footer
Dril l thru Report
Text Decoration
Currency Format
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 Sales.SalesOrderHeader ON Sales.SalesTerritory.TerritoryID = Sales.SalesOrderHeader.TerritoryID AND
18
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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)
19
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ Set Font->Decoration for SalesOrderNo. As ‘Underline’
EXERCISE 7: PRODUCT CATALOG
LEARNING POINTS:
Data bound images
Document Map
Sorting
Page breaks
Nested Data Regions
STEPS
20
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
▪ 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 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
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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
LEARNING POINTS:
Charts
Grouping
Sorting
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
22
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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 BUDGETFROM 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:
Data Pane: Set the DataSetName
o Add three CategoryGroups
23
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
:=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
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
II MANAGING REPORTS
EXERCISE:
LEARNING POINTS:
Standard subscription
Data Driven subscription
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:
Select the radio button “A Custom Data Source”
Connection Type: Microsoft SQL Server
connection string: Datasource=
localhost;init ialcatalog=adventureworks
25
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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.
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].
[subscriberdetail] ' ) and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[subscriberdetail]
GO
26
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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:
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
27
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
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:
Select * from subscriberdetail
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.
II URL ACCESS
EXERCISE:
LEARNING POINTS:
28
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
URL Access To Report Server
SCENARIOS
▪ Use Command Parameter – ListChildren, Render
▪ Render by specifying Format property
▪ Pass a parameter and render a report that is parameterized
III PROGRAMMATIC ACCESS TO REPORTING WEB
SERVICE
EXERCISE:
LEARNING POINTS:
URL Access To Report Server
Performing Management activities
Programmatic Generation of RDL
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
29
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
List all items in a given path (ListChildren method)
List all properties of a given item – folder or report item
(GetProperties method)
Create a new Folder (CreateFolder method)
Create a Subscription (CreateSubscription method)
▪ 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);
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());
30
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
} 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); }
}
IV PROGRAMMATIC GENERATION OF REPORT FILE
LEARNING POINTS:
Using API to create a report definition programmatically
▪ Copy the following structure of the RDL Code:
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
31
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
using System.Xml;
namespace SampleRDLGenerator
{
class RdlGenerator
{
SqlConnection m_connection;
string m_connectString;
string m_commandText;
ArrayList m_fields;
public static void Main()
{
RdlGenerator myRdlGenerator = new RdlGenerator();
myRdlGenerator.Run();
}
public void Run()
{
try
{
/ / Call methods to create the RDL
this.OpenConnection();
this.GenerateFieldsList();
this.GenerateRdl();
32
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
Console.WriteLine("RDL fi le generated successfully.");
}
catch (Exception exception)
{
Console.WriteLine("An error occurred: " +
exception.Message);
}
f inally
{
/ / Close the connection string
m_connection.Close();
}
}
public void OpenConnection()
{
/ / TODO: Open a connection to the sample database
}
public void GenerateFieldsList()
{
/ / TODO: Generate a l ist of f ields for a report query
}
public void GenerateRdl()
33
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
{
/ / TODO: Generate RDL using XmlTextWriter
}
}
}
▪ Create Connection to the AdventureWorks Database as follows:
Replace the Open connection method by the code below
public void OpenConnection()
{
/ / Create a connection object
m_connection = new SqlConnection();
/ / Create the connection string
m_connectString = "data source=localhost; init ial
catalog=AdventureWorks;integrated security=SSPI";
m_connection.ConnectionString = m_connectString;
/ / Open the connection
m_connection.Open();
}
▪ Generate the filed list using a query as follows:
34
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
Use Array List for storing the fields generated thru the
query as below:
public void GenerateFieldsList()
{
SqlCommand command;
SqlDataReader reader;
/ / Executing a query to retrieve a f ields l ist for the report
command = m_connection.CreateCommand();
m_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";
command.CommandText = m_commandText;
/ / Execute and create a reader for the current command
reader =
command.ExecuteReader(CommandBehavior.SchemaOnly);
/ / For each field in the resultset, add the name to an array l ist
35
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
m_fields = new ArrayList();
for ( int i = 0; i <= reader.FieldCount - 1; i++)
{
m_fields.Add(reader.GetName(i));
}
}
▪ Use the XMLTextWriter class to generate the raw RDL File. Use the
connection string and the field list generated in open Connection
method and the Generate fields method as follows:
public void GenerateRdl()
{
/ / Open a new RDL fi le stream for writing
FileStream stream;
stream = File.OpenWrite("Report1.rdl");
XmlTextWriter writer = new XmlTextWriter(stream,
Encoding.UTF8);
/ / Causes child elements to be indented
writer.Formatting = Formatting.Indented;
/ / Report element
writer.WriteProcessingInstruction("xml", "version=\"1.0\"
encoding=\"utf-8\"");
36
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
writer.WriteStartElement("Report");
writer.WriteAttributeString("xmlns", null ,
"http:/ /schemas.microsoft.com/sqlserver/reporting/2003/10/reportd
efinition");
writer.WriteElementString("Width", "6in");
/ / DataSource element
writer.WriteStartElement("DataSources");
writer.WriteStartElement("DataSource");
writer.WriteAttributeString("Name", null , "DataSource1");
writer.WriteStartElement("ConnectionProperties");
writer.WriteElementString("DataProvider", "SQL");
writer.WriteElementString("ConnectString", m_connectString);
writer.WriteElementString("IntegratedSecurity", "true");
writer.WriteEndElement(); / / ConnectionProperties
writer.WriteEndElement(); / / DataSource
writer.WriteEndElement(); / / DataSources
/ / DataSet element
writer.WriteStartElement("DataSets");
writer.WriteStartElement("DataSet");
writer.WriteAttributeString("Name", null , "DataSet1");
/ / Query element
writer.WriteStartElement("Query");
writer.WriteElementString("DataSourceName", "DataSource1");
37
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
writer.WriteElementString("CommandType", "Text");
writer.WriteElementString("CommandText", m_commandText);
writer.WriteElementString("Timeout", "30");
writer.WriteEndElement(); / / Query
/ / Fields elements
writer.WriteStartElement("Fields");
foreach (string fieldName in m_fields)
{
writer.WriteStartElement("Field");
writer.WriteAttributeString("Name", null , f ieldName);
writer.WriteElementString("DataField", null , f ieldName);
writer.WriteEndElement(); / / Field
}
/ / End previous elements
writer.WriteEndElement(); / / Fields
writer.WriteEndElement(); / / DataSet
writer.WriteEndElement(); / / DataSets
/ / Body element
writer.WriteStartElement("Body");
writer.WriteElementString("Height", "5in");
/ / ReportItems element
writer.WriteStartElement("ReportItems");
38
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
/ / Table element
writer.WriteStartElement("Table");
writer.WriteAttributeString("Name", null , "Table1");
writer.WriteElementString("DataSetName", "DataSet1");
writer.WriteElementString("Top", ".5in");
writer.WriteElementString("Left", " .5in");
writer.WriteElementString("Height", " .5in");
writer.WriteElementString("Width", (m_fields.Count * 1.5) +
"in");
/ / Table Columns
writer.WriteStartElement("TableColumns");
for ( int i = 0; i < m_fields.Count; i++)
{
writer.WriteStartElement("TableColumn");
writer.WriteElementString("Width", "1.5in");
writer.WriteEndElement(); / / TableColumn
}
writer.WriteEndElement(); / / TableColumns
/ / Header Row
writer.WriteStartElement("Header");
writer.WriteStartElement("TableRows");
writer.WriteStartElement("TableRow");
39
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
writer.WriteElementString("Height", " .25in");
writer.WriteStartElement("TableCells");
foreach (string fieldName in m_fields)
{
writer.WriteStartElement("TableCell");
writer.WriteStartElement("ReportItems");
/ / Textbox
writer.WriteStartElement("Textbox");
writer.WriteAttributeString("Name", null , "Header" +
fieldName);
writer.WriteStartElement("Style");
writer.WriteElementString("TextDecoration", "Underline");
writer.WriteEndElement(); / / Style
writer.WriteElementString("Top", "0in");
writer.WriteElementString("Left", "0in");
writer.WriteElementString("Height", " .5in");
writer.WriteElementString("Width", "1.5in");
writer.WriteElementString("Value", f ieldName);
writer.WriteEndElement(); / / Textbox
writer.WriteEndElement(); / / ReportItems
writer.WriteEndElement(); / / TableCell
}
40
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
writer.WriteEndElement(); / / TableCells
writer.WriteEndElement(); / / TableRow
writer.WriteEndElement(); / / TableRows
writer.WriteEndElement(); / / Header
/ / Details Row
writer.WriteStartElement("Details");
writer.WriteStartElement("TableRows");
writer.WriteStartElement("TableRow");
writer.WriteElementString("Height", " .25in");
writer.WriteStartElement("TableCells");
foreach (string fieldName in m_fields)
{
writer.WriteStartElement("TableCell");
writer.WriteStartElement("ReportItems");
/ / Textbox
writer.WriteStartElement("Textbox");
writer.WriteAttributeString("Name", null , f ieldName);
writer.WriteStartElement("Style");
writer.WriteEndElement(); / / Style
writer.WriteElementString("Top", "0in");
writer.WriteElementString("Left", "0in");
writer.WriteElementString("Height", " .5in");
41
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
writer.WriteElementString("Width", "1.5in");
writer.WriteElementString("Value", "=Fields!" + fieldName +
".Value");
writer.WriteElementString("HideDuplicates", "DataSet1");
writer.WriteEndElement(); / / Textbox
writer.WriteEndElement(); / / ReportItems
writer.WriteEndElement(); / / TableCell
}
/ / End Details element and children
writer.WriteEndElement(); / / TableCells
writer.WriteEndElement(); / / TableRow
writer.WriteEndElement(); / / TableRows
writer.WriteEndElement(); / / Details
/ / End table element and end report definition f i le
writer.WriteEndElement(); / / Table
writer.WriteEndElement(); / / ReportItems
writer.WriteEndElement(); / / Body
writer.WriteEndElement(); / / Report
/ / Flush the writer and close the stream
writer.Flush();
stream.Close();
42
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
}
▪ Build the project.
▪ View the report generated by the RDL file in the bin directory.
43
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
V CREATING AND USING A REPORT MODEL
LEARNING POINTS:
Creating a Report Model
Using Report Builder
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:
HumanResources.Employee
Person. Contact
Person.StateProvince
Purchasing.VendorContact
Sales.Individual
Sales.SalesOrderHeader
Sales.ContactCreditCard
Sales.Customer
Sales.Store
44
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
Sales.CustomerAddress
Sales.SalesTerritory
Sales.SalesTerritoryHistory
Sales.StoreContact
Sales.SalesPerson
Sales.SalesOrderDetail
▪ Create a new Report Model.
Leave all defaults in the Report Model wizard.
Run the Report Model wizard.
▪ Build and deploy the project.
▪ Open the webpage http://localhost/reports .
▪ Select the Models-> Report builder.
▪ In the Report Builder, Create a new report :
Add Title as Sales Territory Report.
Drop the ‘Sales Territory’ Entity from the Explorer’s list
into the report layout area labeled ‘Drop Column Field’.
In the Explorer’s list select ‘Sales People as Territory’ ->
Sales Person->SalesPerson->Contact.
45
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
From the Fields list, select ‘First Name’ & ‘Last Name’ and
drop it to the right of Sales Territory column in the report
layout.
In the Explorer’s list, Select ‘Sales Person->Sales Order
Headers’
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.
In the toolbar, Select ‘Filter’.
In the Explorer list, select the Sales Person->Sales Order
header Entity.
From the Fields list, expand ‘Order Date’. Drop Order Year
and Order Month fields into the data area and specify the
filter value in the text boxes:
OrderYear = 2002
OrderMonth = 3
Save the Report definition.
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:
Number-> defined formats ->$ 1,234.56.
Run the Report.
46
Exercise Document on Reporting Services
SymIndia
SQL SERVER YUKON
*** End of Document ***
47