Reporting Service添加级联参数
以产品小类大类为例:
1.添加大类数据集,CategoryValues
SELECT DISTINCT Name AS Category FROM Production.ProductCategory
2.添加小类数据集,SubcategoryValues
SELECT DISTINCT PSC.Name AS Subcategory
FROM Production.ProductSubcategory AS PSC
INNER JOIN Production.ProductCategory AS PC
ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE PC.Name = (@Category)
3.在“报表数据”中添加参数@Category,并将参数可用值绑定到CategoryValues数据集,值字段和标签字段都为:Category。
4.同样的添加参数@Subcategory,并将参数可用值绑定到SubcategoryValues数据集,值字段和标签字段都为:Subcategory。这样,在报表查看器中选择了一个产品大类,就会自动将@Category参数传递到SubcategoryValues数据集的查询语句中运行,并自动将结果绑定到Subcategory下拉框了
5.添加统计详细数据集,类似下列的语句:
SELECT
PC.Name AS Category,
PSC.Name AS Subcategory,
P.Name AS Product,
SOH.[OrderDate],
SOH.SalesOrderNumber,
SD.OrderQty,
SD.LineTotal
FROM [Sales].[SalesPerson] SP
INNER JOIN [Sales].[SalesOrderHeader] SOH
ON SP.[SalesPersonID] = SOH.[SalesPersonID]
INNER JOIN Sales.SalesOrderDetail SD
ON SD.SalesOrderID = SOH.SalesOrderID
INNER JOIN Production.Product P
ON SD.ProductID = P.ProductID
INNER JOIN Production.ProductSubcategory PSC
ON P.ProductSubcategoryID = PSC.ProductSubcategoryID
INNER JOIN Production.ProductCategory PC
ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE (PC.Name = (@Category)
AND PSC.Name = (@Subcategory)
AND P.Name = (@Product))
6.在“设计”视图中,添加一个表,拖放需要显示的字段。
7.在报表查看器工具栏上,单击“查看报表”,此时就可以选择产品大类,自动关联产品小类,产品小类选择,如此直到统计详细数据集需要的参数都取到以后,点击“确定”按钮就能看到统计结果了。