共用方式為


教學課程:定義資料表報表的資料集 (Reporting Services)

當您為編頁報告定義資料來源之後,就可以為資料來源定義資料集。 在 Reporting Services 中,報表所用的資料是包含在資料集中。 資料集含有指向資料來源的指標和報表要使用的查詢、導出欄位和變數。

在本教學課程中,您已:

  • 定義資料表報表的資料集。
  • 建立 Transact-SQL 查詢以擷取銷售訂單資訊。

必要條件

定義報表資料的 Transact-SQL 查詢

建立 Transact-SQL 查詢,從 AdventureWorks2022 資料庫擷取銷售訂單資訊。

  1. 在 Visual Studio 中開啟您的銷售訂單報告定義檔案 (.rdl)。

  2. [報表資料] 窗格中,選取 [新增]>[資料集...][資料集屬性] 對話方塊隨即開啟,並顯示 [查詢] 區段。

    [資料集屬性] 對話方塊的螢幕擷取畫面,其中已醒目提示查詢選項。

  3. [名稱] 文字方塊中,輸入「AdventureWorksDataset」。

  4. 選取 [使用內嵌在我的報表中的資料集] 的選項。

  5. [資料來源] 下拉式方塊中,選取 AdventureWorks2022

  6. 針對 [查詢類型],選取 [文字] 選項。

  7. [查詢] 文字輸入框中,輸入 (或複製並貼上) 下列 Transact-SQL 查詢。

    SELECT
       soh.OrderDate AS [Date],
       soh.SalesOrderNumber AS [Order],
       pps.Name AS [Subcat],
       pp.Name as [Product],
       SUM(sd.OrderQty) AS [Qty],
       SUM(sd.LineTotal) AS [LineTotal]
    FROM Sales.SalesPerson sp
    INNER JOIN Sales.SalesOrderHeader AS soh
          ON sp.BusinessEntityID = soh.SalesPersonID
       INNER JOIN Sales.SalesOrderDetail AS sd
          ON sd.SalesOrderID = soh.SalesOrderID
       INNER JOIN Production.Product AS pp
          ON sd.ProductID = pp.ProductID
       INNER JOIN Production.ProductSubcategory AS pps
          ON pp.ProductSubcategoryID = pps.ProductSubcategoryID
       INNER JOIN Production.ProductCategory AS ppc
          ON ppc.ProductCategoryID = pps.ProductCategoryID
    GROUP BY ppc.Name, soh.OrderDate, soh.SalesOrderNumber, pps.Name, pp.Name,soh.SalesPersonID  
    HAVING ppc.Name = 'Clothing'
    
  8. (可選) 選取 [查詢設計工具] 按鈕。 查詢會顯示在以文字為基礎的 [查詢設計工具] 中。 在 [查詢設計工具] 工具列上,選取 [執行] 按鈕,以檢視查詢的結果 ()。 在 AdventureWorks2022 資料庫中,顯示的資料集包含 4 個資料表中的 6 個欄位。 查詢會使用別名之類的 Transact-SQL 功能。 例如,SalesOrderHeader 資料表稱為 soh

  9. 選取 [確定] 結束 [查詢設計工具]。

  10. 選取 [確定] 結束 [資料集屬性] 對話方塊。 [報表資料] 窗格會顯示 AdventureWorksDataset 資料集和欄位。

    [資料集] 資料夾的螢幕擷取畫面,其中顯示 AdventureWorksDataset 及其字段。

後續步驟