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:

在开始使用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

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

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

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

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/

如何创建SQL Server报告服务(SSRS)报告相关推荐

  1. 安装和配置SQL Server Reporting Services (SSRS)

    目录 什么是SQL Server报告服务(SSRS)? 先决条件 安装SQL Server报告服务(SSRS) 配置SQL Server报告服务 结论 在本文中,我们将在Windows机器上配置Mic ...

  2. 如何使用SQL Server主数据服务替换硬编码的查找

    介绍 (Introduction) A big part of the technical debt in my organization's data warehouse (DW) and busi ...

  3. 学习SQL:使用日期和时间函数创建SQL Server报表

    In the previous two articles of this series, we've discussed how to create a report and how to use b ...

  4. 使用SQL Server分析服务定位目标用户

    如何定位目标用户,在任何一个业务单元中都是一个很重要的话题,尤其在预算有限的情况下,如何获得活动的最大收益,目标用户的定位都是很重要的手段. 本文将介绍如何通过SQL Server分析服务(SSAS) ...

  5. [翻译]使用C#创建SQL Server的存储过程(Visual Studio 2005 + SQL Server 2005)

    原文地址:http://www.dotnetbips.com/articles/70eff218-3da0-4f6f-8f8d-eeea65193f2c.aspx[原文×××] [翻译]使用C#创建S ...

  6. 完整的SQL Server邮件服务

    目录 介绍 配置数据库邮件 第1步 第2步 第3步 第4步 第5步 SQL Server作业代理步骤 第1步 第2步 第3步 第4步 第5步 第6步 第7步 第8步 第9步 第10步 第11步 第12 ...

  7. SQL Server 机器学习服务-概述与实战

    (本文2020年1月4日首发于D-BI) 前述 新年第一篇,去旧迎新.本文内容,既旧也新.旧之处在于,SQL Server 机器学习服务是微软在SQL Server 2016 中就引入的新功能,但当时 ...

  8. SQL Server (MSSQLSERVER) 服务因 2148081668 服务性错误而停止。

    https://zhidao.baidu.com/question/151448005.html 具体步骤: 运行-> 输入:"services.msc" ->找到 & ...

  9. Windows下启动停止SQL Server 2005服务

    很多技术爱好者的电脑上总是安装了很多软件,包括应用软件.开发工具软件及数据库软件,但是随着时间的流逝,慢慢地电脑上装的软件已经超出了电脑本身所能承载的量了,因而出现了电脑运行速度慢等问题.同时,也有一 ...

最新文章

  1. 解决Debian 9 iwlwifi固件缺失导致无法连接无线网络的问题
  2. R语言 非中心化F分布
  3. phpstudy一直自动停止启动_发动机自动启停,到底是省油还是毁车?
  4. Mongodb 集群加keyFile认证
  5. git个人使用总结 —— idea命令行、撤销commit (未完待续)
  6. Shell练习题(持续更新)
  7. IOS的UIPickerView 和UIDatePicker
  8. 在线的SA 绘图工具-Mockups
  9. 从化工技术员到微软最有价值专家(MVP)--我的IT从业路
  10. 关于Apache Struts2远程执行任意命令漏洞的紧急通报
  11. 吃自己的狗食,用自己的产品——再谈华为芯片
  12. 第一部分 第三章 1039-1058 答案合集
  13. 文本分析软件-智分析 SmartAnalyze
  14. 三凌PLC源码,STM32F205VCT6主控PLC控制器板,已批量生产
  15. 博士申请 | 皇家墨尔本理工大学鲍芝峰教授招收数据挖掘方向全奖博士生
  16. Oracle loap函数,oracle分区表执行计划
  17. hash碰撞解决方法
  18. 小公司程序员怎么进大公司
  19. 手机怎么把几个PDF文件合并到一起?教你一分钟搞定
  20. 【无代码体验】用鲸智搭替换Excel表管理数据

热门文章

  1. python 函数嵌套 报错_《Python》 函数嵌套、闭包和迭代器
  2. SPFA求最短路——Bellman-Ford算法的优化
  3. python实现句子反转
  4. ubuntu程序安装方法
  5. 在C# 中 如何限制在文本框(textBox)中输入的类型为正整数
  6. 在DataGridView中的列头添加复选框
  7. VUE 生命周期图示
  8. TypeScript与React中如何使用ref
  9. vue中的VNode
  10. 【Vue2.0】—组件(十一)