星期日, 5月 31, 2015

[SSRS] 串聯參數

根據 第 4 課:加入串聯參數 (SSRS) 這篇的練習

主報表設定

dsMain DataSet 語法 - 報表主語法
USE [AdventureWorks2014]
GO

SELECT 
    PC.Name AS Category,
    PSC.Name AS Subcategory,
    P.Name AS Product,
    SOH.[OrderDate],
    SOH.SalesOrderNumber,
    SD.OrderQty, 
    SD.LineTotal
FROM [Sales].[SalesPerson] AS SP 
    JOIN [Sales].[SalesOrderHeader] AS SOH ON SP.[BusinessEntityID] = SOH.[SalesPersonID]
    JOIN Sales.SalesOrderDetail AS SD ON SD.SalesOrderID = SOH.SalesOrderID
    JOIN Production.Product AS P ON SD.ProductID = P.ProductID
    JOIN Production.ProductSubcategory AS PSC ON P.ProductSubcategoryID = PSC.ProductSubcategoryID
    JOIN Production.ProductCategory AS PC ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE PC.ProductCategoryID = @CategoryID
    AND PSC.ProductSubcategoryID = @SubcategoryID
    AND P.ProductID = @ProductID
根據主語法產生的精靈報表

[SSRS] 串連參數-2


下拉選單設定

dsProductCategory DataSet 語法 - 大分類下拉式選單用
USE [AdventureWorks2014]
GO

SELECT 
    ProductCategoryID , 
    Name AS CategoryName 
FROM Production.ProductCategory
dsProductSubCategory DataSet 語法 - 子分類下拉選單用
USE [AdventureWorks2014]
GO

SELECT 
    PSC.ProductSubcategoryID , 
    PSC.Name AS SubcategoryName
FROM Production.ProductCategory AS PC
    JOIN Production.ProductSubcategory AS PSC ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE PC.ProductCategoryID = @CategoryID
dsProduct DataSet 語法 - 產品下拉選單用
USE [AdventureWorks2014]
GO

SELECT 
    P.ProductID , 
    P.Name AS ProductName
FROM Production.Product AS P
    JOIN Production.ProductSubcategory PSC ON P.ProductSubcategoryID = PSC.ProductSubcategoryID
    JOIN Production.ProductCategory PC ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE PC.ProductCategoryID = @CategoryID
    AND PSC.ProductSubcategoryID = @SubcategoryID
報表資料內容

[SSRS] 串連參數-1

以 @CategoryID 當成範例來紀錄設定過程

參數 => @CategoryID => 滑鼠右鍵 => 參數屬性

[SSRS] 串連參數-5

報表參數屬性 => 一般 Tag => 提示,從 CategoryID 改為 大分類

[SSRS] 串連參數-6

可用的值 Tag => 從查詢取得值 =>
  • 資料集:dsProductCategory
  • 值欄位:ProductCategoryID
  • 標籤欄位:CategoryName

[SSRS] 串連參數-3

@SubcategoryID 和 @ProductID 參數,請以此類推設定

設定 OrderDate 欄位格式 - Format:yyyy/MM/dd

[SSRS] 串連參數-4

預覽結果

三個下拉選單,只有大分類可以選擇

[SSRS] 串連參數-7

大分類選擇後,子分類就可以選擇

[SSRS] 串連參數-8

子分類選擇後,產品下拉選單就可以動作

[SSRS] 串連參數-9

報表結果

[SSRS] 串連參數-10

沒有留言:

張貼留言