sql server安裝實驗報告,如何創建SQL Server報告服務(SSRS)報告

 2023-10-18 阅读 30 评论 0

摘要:SQL Server Reporting Services (SSRS) is part of Microsoft SQL Server services since version 2000. If you are an ordinary user with a basic knowledge of SQL, this article will help you in creating your first SSRS report. 自2000版以來,SQL Server Rep

SQL Server Reporting Services (SSRS) is part of Microsoft SQL Server services since version 2000. If you are an ordinary user with a basic knowledge of SQL, this article will help you in creating your first SSRS report.

自2000版以來,SQL Server Reporting Services(SSRS)是Microsoft SQL Server服務的一部分。如果您是具有SQL基本知識的普通用戶,則本文將幫助您創建第一個SSRS報告。

創建SSRS報告的要求 (Requirements for creating a SSRS report)

Before you begin using SSRS and creating reports you must have:

sql server安裝實驗報告。 在開始使用SSRS和創建報告之前,您必須具有:

  • Microsoft SQL Server 2014 database engine

    Microsoft SQL Server 2014數據庫引擎
  • SQL Server 2014 reporting service (SSRS)

    SQL Server 2014報告服務(SSRS)
  • SQL Server data tools SQL Server數據工具
  • AdventureWorks2012 database is used for this article, as AdventureWorks2012數據庫作為data source. 數據源

創建報告服務器項目 (Create a report server project)

The first thing to do is to create a report server project because we will need this later for saving report definition files and any other files that you need for creating SSRS reports.

要做的第一件事是創建報告服務器項目,因為稍后我們將需要它來保存報告定義文件以及創建SSRS報告所需的任何其他文件。

  • SQL Server Data Tools. Click on the SQL Server數據工具 。 單擊File menu, find 文件菜單,找到New and then 新建 ,然后找到Project.項目
  • Business Intelligence. Business Intelligence
  • Reporting Services and then Reporting Services ,然后單擊Report Server Project. Report Server Project
  • Report test in 名稱”中鍵入Name “報告測試”
  • OK to finish. 確定”完成。



    創建文明村情況報告?

創建一個新的報告定義文件 (Create a new report definition file)

  • Solution Explorer, and then right-click on the 解決方案資源管理器” ,然后右鍵單擊“ Reports folder. In the 報告”文件夾。 在“ Add section click 添加”部分中,單擊“ New Item. 新建項目”
  • Add New Item, click 添加新項 ”窗口中,單擊Report. “報告”
  • Design view you define your report layout, and in the 設計視圖中,您可以定義報告布局,在Preview view you can run your report. 預覽視圖中,您可以運行報告。

定義數據源和數據集 (Defining data source and dataset)

Setting up a connection

建立連接

創造服務, In order to retrieve data from a database or from some other resource, you will need to define the data source. In the following section, you will see how you can define the data source. We will use AdventureWorks2012 database as an example.

為了從數據庫或其他資源中檢索數據,您將需要定義數據源。 在下一節中,您將看到如何定義數據源。 我們將以AdventureWorks2012數據庫為例。

  • View menu find and click Report Data, then 查看”菜單中,找到并單擊“報告數據”,然后單擊“ New and after that 新建 ”,然后單擊該Data Source數據源。
  • Type AdventureWorks2012 in the field Name
  • 名稱字段中輸入AdventureWorks2012
  • Embedded connection 嵌入式連接
  • Microsoft SQL Server Microsoft SQL Server
  • Connection string field type: 連接字符串”字段中,輸入:




程序創建服務、Note: If the database is not on the local computer, replace localhost with name of your database server instance.

注意:如果數據庫不在本地計算機上,則將localhost替換為數據庫服務器實例的名稱。

  • Credentials and then 憑據” ,然后Use Windows Authentication. 使用“ Windows身份驗證”。
  • OK, and you’re done. OK ,您就完成了。



使用服務?Define a T-SQL query for report data

定義報告數據的T-SQL查詢

In this section you will learn how to specify a dataset. You will need some basic SQL knowledge in order to create a query and define what information you will need from your database. The query you will see is just an example, and for your own purposes and database, you will have to change that step.

在本節中,您將學習如何指定數據集 。 您將需要一些基本SQL知識才能創建查詢并定義數據庫中需要的信息。 您將看到的查詢只是一個示例,對于您自己的目的和數據庫,您必須更改該步驟。

  • In the Report Data pane find and click New, and then Dataset.
  • 在“報表數據”窗格中,找到并單擊“ 新建” ,然后單擊 數據集”
  • Dataset Properties dialog box as 數據集屬性”對話框中,作為“ Name type DataSet1 名稱”鍵入DataSet1
  • Use a dataset embedded in my report. 使用報表中嵌入的數據集
  • data source, 數據源
  • Text as a Text作為Type, and type this into the Query input: Type ,然后在Query輸入中輸入以下內容:

    ?
    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'
    Defining a Dataset for the Table Report (Reporting Services)為表格報表定義數據集(Reporting Services)



    報告格式。

Note: soh, pps, sd, pp, ppc are just shorter names for tables that we have in AdventureWorks2012 database.

注意: soh,pps,sd,pp,ppc只是AdventureWorks2012數據庫中表的簡稱。

如何將表和字段添加到報表布局 (How to add a table and fields to a report layout)

After finishing with previous technical details, we can start with more interesting things, like designing your first SSRS report. This part is easy because instead of writing code, you can drag-and-drop graphic icons into the report format. This section will show you how to add Table and Fields to your report.

在完成了先前的技術細節之后,我們可以從更有趣的事情開始,例如設計您的第一個SSRS報告。 這部分很容易,因為您無需編寫代碼,而是可以將圖形圖標拖放到報告格式中。 本節將向您展示如何將表和字段添加到報告中。

  • In the View menu click Toolbox, then find and click Table and drag the mouse to the design area.
  • 在“ 視圖”菜單中,單擊“ 工具箱”,然后找到并單擊“ 表” 然后將鼠標拖動到設計區域。
  • Dataset1 in order to see all the fields. Dataset1以便查看所有字段。
  • Drag one of the field (e.g. field Date) from Report Data to the column in the table

    將字段之一(例如,日期字段)從報表數據拖到表中的列




Preview report

預覽報告

If you want to preview your report to see how it all looks, to correct errors, to correct issues or to verify design and data connection, click tab Preview.

如果要預覽報告以查看其外觀,更正錯誤,更正問題或驗證設計和數據連接,請單擊“ 預覽”選項卡

Tips and tricks

技巧和竅門

An easier way to add a table is to right-click on the design surface, click Insert and then click Table.

添加表的一種更簡單的方法是右鍵單擊設計圖面,單擊“ 插入” ,然后單擊“ 表”。

如何格式化報告 (How to format your Report)

Format currency and date

格式化貨幣和日期

If you want to format Date field to show only the date, follow the steps below:

如果要格式化日期字段以僅顯示日期,請按照以下步驟操作:

  • Design tab, right-click the desired cell, then click 設計”選項卡中,右鍵單擊所需的單元格,然后單擊“ Text Box Properties. 文本框屬性”。
  • Number, then in the field數字 ,然后在 Category click 類別字段中單擊Date 日期
  • Type select date format you want, and click 類型”中選擇所需的日期格式,然后單擊“ OK to finish. 確定”完成。



If in your table you have a field that holds information about currency, but you only see ordinary numbers, you can format that field to display a number as currency:

如果表中有一個字段,其中包含有關貨幣的信息,但您只看到普通數字,則可以格式化該字段以將數字顯示為貨幣:

  • Design tab, right-click the desired cell, then click 在設計選項卡上,右鍵單擊所需的單元格,然后單擊Text Box Properties. 文本框屬性。
  • Number, then in the field 數字 ,然后在Category click 類別字段中單擊Currency 貨幣
  • In accordance to your need you can change defaults

    根據您的需要,您可以更改默認值
  • OK to finish. 確定完成。



Changing column width and text style

更改列寬和文本樣式

You also have an option to change text style (font, size etc.), and to change column width. Column width you can change by simply dragging the columns to the desired size.

您還可以選擇更改文本樣式(字體,大小等)并更改列寬 。 只需將列拖動到所需的大小,即可更改列寬。

Text style you can change by clicking the Format menu. In Format menu find Font, then click whatever you need (bold, italic, etc.)

您可以通過單擊格式菜單來更改文本樣式。 在“ 格式”菜單中,找到“ 字體” ,然后單擊所需的任何內容(粗體,斜體等)。

添加分組 (Adding Grouping)

If you want to make data set in your SSRS report do the following:

如果要在SSRS報告中設置數據,請執行以下操作:

  • Design tab, and then choose pane 設計選項卡,然后選擇窗格Row Groups 行組
  • Row Groups 行組”中
  • From your report pane drag some other field you want to group.

    從報告窗格中拖動要分組的其他字段。
  • Delete the old columns to the double line.

    刪除舊列到雙行。
  • Text Box Properties, the next steps are the same like in the formatting report section. 文本框屬性” ,接下來的步驟與“格式報告”部分中的相同。



Tips and tricks

技巧和竅門

You can do the same by right-clicking on the surface and clicking View, and then Grouping.

您可以通過右鍵單擊表面并單擊“ 視圖” ,然后單擊 分組”來執行相同的操作

加總 (Adding totals)

Total is the sum of numeric, non-null data in the data region, and if you want to add totals for a group, you can do that by clicking Add Total for the group in the Grouping pane, and if you want to add totals for an individual cell just click Add Total for the cell.

總計是數據區域中數字非空數據的總和,如果要添加組的總計,則可以通過在“分組”窗格中單擊該組的“ 添加總計”來完成,如果要添加總計對于單個單元格,只需單擊該單元格的“ 添加總計 ”即可。

Add a daily total and grand total

添加每日總計和總計

  • and choose 并選擇Add total, then click 添加總計 ,然后單擊After之后 .
  • Type Daily to format a new name, Daily Total

    鍵入Daily以設置新名稱Daily Total
  • After that, select the new cell [Daily Total], two Sum cells and the empty cell you see between them.

    之后,選擇新的單元格[Daily Total],兩個Sum單元格以及在它們之間看到的空單元格。
  • Format menu, choose background color. We chose color orange. 格式菜單上,選擇背景色。 我們選擇了橙色。



  • Add total, and then 添加總計” ,然后選擇“ After之后” .
  • Type Grand to format a new name, Grand Total

    鍵入Grand以格式化新名稱Grand Total
  • Select the new cell [Grand Total], the two [Sum] cells and the empty cell you see between them.

    選擇新的單元格[總計],兩個[總和]單元格以及在它們之間看到的空單元格。
  • Format menu, choose background color. We chose color light-blue. 格式菜單上,選擇背景色。 我們選擇淺藍色。



Tips and tricks

技巧和竅門

After you add total, you can change the default function Sum. There is a list of different function you can use (avg, count, etc.).

添加總計后,可以更改默認功能總和。 您可以使用不同功能的列表(平均,計數等)。

將您的報告發布到報告服務器 (Publish your Report to the report server)

Finally, when you finished with creating your first SSRS report, you may want to publish the report:

最后,完成創建第一個SSRS報告后,您可能要發布該報告:

  • Project menu click 項目菜單中單擊Test report Properties 測試報告屬性
  • Put your report server’s name in the field TargetServerURL, then click OK.

    將報表服務器的名稱放在TargetServerURL字段中,然后單擊“確定”。
  • Build menu click 生成”菜單中,單擊“ Deploy Test report. You will get a message that indicates whether you have successful or unsuccessful deployment. 部署測試報告” 。 您將收到一條消息,指出您是成功還是失敗的部署。

Note: A problem will occurred if you don’t have permissions on the report server or if you have been using SSDT with administrator privileges.

注意:如果您對報表服務器沒有權限,或者您一直在使用具有管理員權限的SSDT,則會出現問題。

Most common problems

最常見的問題

The most common problem in publishing the report to the report server is configuring the target server URL.

將報表發布到報表服務器中最常見的問題是配置目標服務器URL。

The first step that you need to do in configuration is to launch the SQL Server Reporting Service Configuration Manager and connect to the Reporting Service.

在配置中需要做的第一步是啟動SQL Server Reporting Service 配置管理器并連接到Reporting Service

Create SSRS report

After that in section Web Service URL you can find URL to the report server.

之后,在“ Web服務URL”部分中,您可以找到報表服務器的URL。

Creating SSRS report shot

In section Report Manager URL you can see URL for viewing and managing reports.

在“ 報告管理器URL”部分中,您可以查看用于查看和管理報告的URL。

Creating SSRS report shot

In the Project menu open the Test report Properties.

項目菜單中,打開測試報告屬性

Note: Prefix “Test report” is name of your report.

注意 :前綴“測試報告”是報告的名稱。

Final step in configure target server URL is to fill the Web Service URL in the TargerServerURL property with correct URL that you find in Report Manager URL.

配置目標服務器URL的最后一步是使用在報表管理器URL中找到的正確URL填充TargerServerURL屬性中的Web服務URL

Creating SSRS report shots 1

Congratulation, you have successfully created your first SSRS report!

恭喜,您已經成功創建了第一個SSRS報告!

參考資料 (References)

Reporting Services (SSRS)
Reporting Services Concepts (SSRS)
Reporting Services Backward Compatibility
Cause and Resolution of Reporting Services Errors

報告服務(SSRS)
報告服務概念(SSRS)
報表服務向后兼容性
Reporting Services錯誤的原因和解決方案

翻譯自: https://www.sqlshack.com/create-sql-server-reporting-services-ssrs-report/

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/144373.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息