介绍 (Introduction)

Far too often we encounter clients that are really too keen to establish all inclusive reports for decision making purposes. While this is super (in principle) oft times these folks will inform you that all the data that is within the tables should be present within the report, and this is not always feasible nor practical.

我们经常会遇到真正渴望创建所有包容性报告以用于决策目的的客户。 尽管这是超级(原则上)的时间,但这些人通常会通知您,表中的所有数据都应存在于报表中,这并不总是可行或不切实际的。

After much thought I came up with an alternative to permit these folks to have their ‘cake and eat it’ and yet not render a cluttered report.

经过深思熟虑后,我想出了一种替代方法,允许这些人吃“蛋糕并吃”,但又不要发表混乱的报告。

It all boils down to what is visible and when it is visible.

一切归结为可见的内容和可见的时间。

入门 (Getting started)

For this exercise (as we have done in past) we shall be utilizing SQL Server Data Tools, hence forward referred to as SSDT.

对于本练习(如我们过去所做的那样),我们将使用SQL Server数据工具,因此向前称为SSDT。

We begin by creating a new “Report Services Project” (see below).

我们首先创建一个新的“ Report Services项目”(见下文)。

We define where the new project will reside and click OK to arrive at my work area.

我们定义新项目将驻留的位置,然后单击“确定”到达我的工作区。

Our first task will be to create a new report.

我们的首要任务是创建一个新报告。

We right click on the “Reports” folder (in the Solution Explorer) select “Add” and then “New Item” see above.

我们右键单击“ Reports”文件夹(在解决方案资源管理器中),选择“ Add”,然后选择“ New Item”,参见上文。

We select “Report” from the “Add New Item” menu (see above). We give our report a name and click OK to exit the “Add New Item” menu. We are returned to our “Drawing Surface”, however we now find ourselves within the Report (that we have just created).

我们从“添加新项”菜单中选择“报告”(见上文)。 我们给报告起一个名字,然后单击“确定”退出“添加新项”菜单。 我们返回到“图纸表面”,但是现在我们可以在刚刚创建的报告中找到自己。

添加新的数据源 (Adding a new data source)

Having created a new report, we now wish to be able to pull the required data from the database tables.

创建新报告后,我们现在希望能够从数据库表中提取所需的数据。

To do so, we must connect to the database(s) concerned. We are going to cover this part at a high level as I have discussed the process in detail in other postings on this website.

为此,我们必须连接到相关的数据库。 我们将在更高层次上介绍这一部分,因为我已经在本网站上的其他帖子中详细讨论了该过程。

We right click on the “Shared Data Sources” tab in the solution explorer and select “Add New Data Source” (see above).

我们右键单击解决方案资源管理器中的“共享数据源”选项卡,然后选择“添加新数据源”(请参见上文)。

We complete the “Shared Data Source Properties” to point to my database (see above). This requires the server name, the database name, how users will authenticate and the name that we wish to utilize for this “Shared Data Source”.

我们完成了“共享数据源属性”以指向我的数据库(请参见上文)。 这需要服务器名称,数据库名称,用户将如何进行身份验证以及我们希望用于此“共享数据源”的名称。

Once completed, we click OK, OK, and OK to exit out from the Data Source editor.

完成后,我们单击“确定”,“确定”和“确定”以退出“数据源”编辑器。

创建我们的第一个数据集 (Creating the first of our datasets)

As I have discussed in earlier articles, datasets may be likened to a bucket. The data source may be likened to a water hose connected to the faucet outside the house (the database). The controls that we place upon our reports, source their data from this dataset (bucket).

正如我在之前的文章中所讨论的,数据集可以比喻为存储桶。 数据源可以比喻为连接到房屋外部水龙头(数据库)的水管。 我们放置在报表上的控件从此数据集(存储桶)中获取数据。

The first of the datasets that we shall be creating will contain the market values of several financial funds that SQL Shack Financial possesses. This data will be pulled from the necessary tables via a SQL Server Stored procedure. This stored procedure will be “called” by the data set at runtime. The dataset will be the source of data for the matrix and line graphs that make up our report. Our stored procedure may be seen below:

我们将要创建的第一个数据集将包含SQL Shack Financial拥有的几种金融基金的市场价值。 这些数据将通过SQL Server存储过程从必要的表中提取。 该存储过程将在运行时被数据集“调用”。 数据集将成为构成我们报告的矩阵图和折线图的数据源。 我们的存储过程如下所示:

Now that our stored procedure has been created, we move back to report project. We must now create our “bucket” to hold the data coming from the database. We right click on the “Dataset” folder and select “Add Dataset” (see below).

现在已经创建了存储过程,我们返回报表项目。 现在,我们必须创建“存储桶”以保存来自数据库的数据。 我们右键单击“数据集”文件夹,然后选择“添加数据集”(见下文)。

We give the dataset a name. In our case we select the name “MarketValue” (see above).

我们给数据集起一个名字。 在我们的例子中,我们选择名称“ MarketValue”(见上文)。

The “Create Dataset Wizard” now needs to understand where the data (that it must pull) resides. We shall select “New” (see the “New” button in the middle of the screen dump above). It should be mentioned at this point that a so called “best practice” is to create local data sources which are applicable at the report level. These local data sources will inherit the connection attributes from the shared data source that we created above. We give our local data source the name “SQLShackFinancialDataSource” (see the top of the screen shot below). This connection string will utilize the SQLShackDS shared data source (see below).

现在,“创建数据集向导”需要了解数据(必须将其拉出)位于何处。 我们将选择“新建”(请参见上方屏幕转储中间的“新建”按钮)。 在这一点上应该提到,所谓的“最佳实践”是创建适用于报告级别的本地数据源。 这些本地数据源将从我们上面创建的共享数据源继承连接属性。 我们将本地数据源命名为“ SQLShackFinancialDataSource”(请参见下面的屏幕快照)。 该连接字符串将利用SQLShackDS共享数据源(请参见下文)。

Our connection string has been created (see below). We click OK to continue. We find ourselves back at the “Choose a data source and create a query” data entry screen.

我们的连接字符串已创建(请参见下文)。 我们单击“确定”继续。 我们回到了“选择数据源并创建查询”数据输入屏幕。

At this point we click the “Stored Procedure” radio button (see above) to let the data source know that the query required to pull the necessary data, resides within a stored procedure. We click OK to exit the “Create Dataset” wizard.

此时,我们单击“存储过程”单选按钮(请参见上文),以使数据源知道提取必要数据所需的查询位于存储过程中。 我们单击“确定”退出“创建数据集”向导。

Opening the newly created dataset, we see the setup that we just created shown to us on the “Query” tab.

打开新创建的数据集,我们在“查询”选项卡上看到刚刚创建的设置。

We now click the “Fields” tab to ascertain just which fields are being pulled by our query (see below).

现在,我们单击“字段”选项卡来确定查询正在提取哪些字段(请参见下文)。

We see that everything is in order. We therefore close out by clicking “OK” and we are returned to my drawing surface (see below).

我们看到一切都井井有条。 因此,我们通过单击“确定”进行关闭,然后返回到我的绘图表面(见下文)。

在矩阵中查看我们的数据 (Viewing our data within a matrix)

We now drag a matrix control (report item) onto our work surface (see below).

现在,我们将矩阵控件(报告项)拖到工作表面上(见下文)。

We must now set the dataset property of the matrix, to capture its source data from our dataset that we just created (see below in the lower right).

现在,我们必须设置矩阵的数据集属性,以从刚创建的数据集中捕获其源数据(请参见右下方的以下内容)。

Having set the dataset property, our next task is to remove the column grouping on the matrix, as this is not required for our exercise. We right click on “Column Group” and select “Delete Group” (see below).

设置完数据集属性后,我们的下一个任务是删除矩阵上的列分组,因为我们的练习不需要这样做。 我们右键单击“列组”,然后选择“删除组”(见下文)。

We are now asked whether we wish to delete the grouping including the data or merely just the grouping. We select JUST THE GROUPING i.e. “Delete group only” (see below).

现在,我们问我们是否要删除包括数据的分组或仅删除分组。 我们选择“仅分组”,即“仅删除组”(请参见下文)。

We click OK to close out of the “Delete Group” dialogue box.

我们单击“确定”以关闭“删除组”对话框。

The astute reader will note that our matrix has but two columns. We actually require four columns. We right click on the light grey “Columns” label within the header of the matrix (see above) and add two columns to the right of THAT column (see below).

精明的读者会注意到,我们的矩阵只有两列。 我们实际上需要四列。 我们右键单击矩阵标题中的浅灰色“ Columns”标签(请参见上文 ),然后在THAT列的右侧添加两列(请参见下文 )。

We now populate the columns with the fields from the dataset (see below).

现在,我们使用数据集中的字段填充列(请参见下文)。

Note that the top row is used as the report column header. I always choose to rename these headers as they are not very ‘pleasing’ to the eye (see below).

请注意,第一行用作报告列标题。 我总是选择重命名这些标头,因为它们不太“令人愉悦”(请参见下文)。

This done, let us see what we have produced. We click “Preview” from the report designer.

完成后,让我们看看我们产生了什么。 我们从报表设计器中单击“预览”。

Our data may be seen above. The format however leaves much to be desired. By clicking in each of the field boxes (within design mode), we are able to change the format.

我们的数据可以在上面看到。 但是,格式还有很多不足之处。 通过单击每个字段框(在设计模式下),我们可以更改格式。

Date is being changed above. Currency is changed below.

日期在上面更改。 货币在下面更改。

In a similar manner we change to appearance of the Average Exchange Rate. Our final matrix is similar to the one shown below:

以类似的方式,我们更改为平均汇率的外观。 我们的最终矩阵类似于以下所示:

In a similar fashion, it is left up to the reader to:

以类似的方式,它由读者自己决定:

  1. Create the “SQLShackFinancialReferenceFundStatus” stored procedure

    创建“ SQLShackFinancialReferenceFundStatus”存储过程

    USE [SQLShackFinancial]
    GO/****** Object:  StoredProcedure [dbo].[SQLShackFinancialReferenceFundStatus
    12/4/2014 9:25:00 AM ******/
    SET ANSI_NULLS ON
    GOSET QUOTED_IDENTIFIER ON
    GOcreate procedure [dbo].[SQLShackFinancialReferenceFundStatus]
    as
    SELECT * from [dbo].[REF_FUND_STATUS]
    GO
  2. Create the necessary dataset utilizing the local data source that we created above and linking that data source to the shared data source “SQLShackDS”.

    利用我们在上面创建的本地数据源创建必要的数据集,并将该数据源链接到共享数据源“ SQLShackDS”。

向我们的报告中添加更多数据 (Adding more data to our report)

In a similar manner to that which has been described above, I have added another matrix to our report (see below). This matrix contains the “Reference fund status” data (see the first matrix below).

以与上述类似的方式,我在报告中添加了另一个矩阵(请参见下文)。 该矩阵包含“参考资金状态”数据(请参见下面的第一个矩阵)。

We now add a few charts to reflect upon our Market Value based data and last but not least, the SQL Shack logo. We end up with the following ‘very busy’ report (see below).

现在,我们添加一些图表以反映基于市场价值的数据,最后但并非最不重要的是SQL Shack徽标。 我们最终得到以下“非常忙”报告(请参阅下文)。

解决这个烂摊子!! (Fixing this mess!!)

In order to consolidate our report and to keep ‘like-minded’ results together, we are going to place all related objects into rectangle controls and utilize the visibility property of THAT rectangle (see below). Thus when the end user wishes to look at Market Value related data, the rectangle containing the Market Value matrix and the 2 graphs will become visible and when the user wishes to view Reference Fund data, the Market Value objects are hidden and the Reference Fund data is displayed.

为了合并我们的报告并保持“志趣相投”的结果在一起,我们将所有相关对象放入矩形控件中, 并利用THAT矩形的可见性属性 (请参见下文)。 因此,当最终用户希望查看与市场价值相关的数据时,包含市场价值矩阵和2个图表的矩形将变得可见,并且当用户希望查看参考基金数据时,市场价值对象被隐藏,参考基金数据被隐藏。被展示。

The rectangle

矩形

The objects being dropped into this rectangle.

对象将放入此矩形。

It is IMPORTANT to note that the visibility property of the rectangle takes higher precedence than the objects contained within the rectangle. Thus when the visibility property of the rectangle is set to “show”, so will the objects within. When the property is set to hidden, so will the objects within the rectangle.

重要的是要注意,矩形的可见性属性比包含在矩形中的对象具有更高的优先级。 因此,当矩形的可见性属性设置为“显示”时,其中的对象也将设置为“显示”。 当属性设置为隐藏时,矩形内的对象也将隐藏。

那么我们如何实现所有这些呢? (So how do we achieve all of this?)

At this point we shall add a parameter called ‘toggle’ to our report. ‘toggle’ will have an initial / default value of 0 (zero). Further the ‘toggle’ parameter is never displayed on the screen and thus is hidden from the user’s view. It will never appear, requesting input from the end user (see below).

此时,我们将在报表中添加一个名为“ toggle”的参数。 'toggle'的初始/默认值为0(零)。 此外,“切换”参数从不显示在屏幕上,因此对用户而言是隐藏的。 它永远不会出现,要求最终用户输入(请参阅下文)。

We shall now set the ‘toggle’ default value which will be 0 (see below).

现在,我们将设置“切换”默认值为0(请参见下文)。

We click OK to leave the “Report Parameter Properties” dialogue box.

我们单击“确定”离开“报告参数属性”对话框。

By moving ALL my objects over slightly to the right of the work surface, we create some extra work space (see below).

通过将我的所有对象稍微移到工作表面的右侧,我们创建了一些额外的工作空间(请参见下文)。

We now add two text boxes to that empty space (see below). One text box has the text “Market Value” and the other “Fund Reference”. While there is a rectangle enclosing these text boxes, the purpose of this rectangle is to keep the text boxes in situ as the remaining rectangles are toggled between ‘appear’ and ‘hidden’.

现在,我们在该空白处添加两个文本框(请参见下文)。 一个文本框包含文本“市场价值”,另一个文本框包含“资金参考”。 尽管有一个矩形将这些文本框围起来,但此矩形的目的是将文本框保持在原位,因为其余矩形在“出现”和“隐藏”之间切换。

激活“市场价值”文本框 (Activating the “Market Value” text box)

We right click on the text box and select ‘Textbox Properties’ from the context menu. The “Text Box Properties” dialogue box is brought into view. We select “Action” (see below).

我们右键单击文本框,然后从上下文菜单中选择“文本框属性”。 出现“文本框属性”对话框。 我们选择“动作”(见下文)。

Opening the “Action” box, we select “Go to report”. For “Specify a report”, we create a recursive call to the report that we are constructing (see below).

打开“操作”框,我们选择“转到报告”。 对于“指定报告”, 我们对正在构建的报告创建一个递归调用 (请参见下文)。

Note that we have added our “toggle” parameter (which we created above) to the “Use these parameters to run the report” section of the properties box and have given it a value of 1. This will be used within the recursive call (see above).

请注意,我们已经在属性框的“使用这些参数运行报告”部分中添加了“切换”参数(我们在上面创建),并将其值设置为1。这将在递归调用中使用(往上看)。

激活“资金状态”文本框 (Activating the “Fund Status” text box)

We repeat the same steps for setting the “Fund Status” text box, HOWEVER we set its toggle value to 2.

我们重复相同的步骤来设置“资金状态”文本框,但是我们将其切换值设置为2。

工作真正的魔术! (Working the REAL magic!!)

Prior to commencing our activities and to give our report a less cluttered look, I rationalized a few things. Not much has changed (see below).

在开始我们的活动并让我们的报告看起来不那么混乱之前,我对一些事情进行了合理化。 变化不大(请参阅下文)。

剪切和粘贴任务 (Cut and Paste tasks)

As discussed above, we shall be placing all related controls into their own respective rectangle controls.

如上所述,我们将所有相关的控件放入各自的矩形控件中。

To achieve this, we “cut” all “Market Value” related objects. Once “cut”, we drag a rectangle control onto the surface, resize it, and then we “paste” the “cut” objects into that rectangle. We have seen this above with the section called “Fixing the mess”.

为此,我们“削减”了所有“市场价值”相关对象。 一旦“剪切”,我们将一个矩形控件拖到曲面上,调整其大小,然后将“剪切”对象“粘贴”到该矩形中。 上面我们在“修复烂摊子”一节中已经看到了这一点。

We repeat this process with the “Reference Fund Status” objects and for the two text boxes that we added (one to show Market Value data and the other to show Reference Fund Status data). The finished rectangles may be seen below:

我们使用“参考基金状态”对象以及添加的两个文本框重复此过程(一个显示市场价值数据,另一个显示参考基金状态数据)。 完成的矩形如下所示:

设置矩形切换 (Setting the Rectangle Toggles)

By right clicking on the “Reference Fund Status rectangle”, we bring up the “Rectangle Properties” dialogue box. We now click on the “Visibility” tab and select the “Show or hide based on an expression” radio button. Opening the “Expression” box we add the following script (see below).

通过右键单击“参考资金状态”矩形,我们将弹出“矩形属性”对话框。 现在,我们单击“可见性”选项卡,然后选择“基于表达式显示或隐藏”单选按钮。 打开“表达式”框,我们添加以下脚本(见下文)。

For the “Reference Fund Status”, we see that the rectangle will be visible when the value of ‘toggle’ is changed to 2 (see above).

对于“参考基金状态”,我们看到,当“切换”的值更改为2时,该矩形将可见(请参见上文)。

As a detailed explanation, when toggle is set to a value of 2, “hidden” becomes FALSE and therefore the contents within the rectangle become visible to the end user (see above).

作为详细说明,将切换设置为2时,“隐藏”变为FALSE ,因此最终用户可以看到矩形内的内容(请参见上文)。

We configure the “Market Value” rectangle in a similar fashion (see below)

我们以类似的方式配置“市场价值”矩形(请参见下文)

让我们旋转一下! (Let us give it a whirl!)

To start our report in Preview mode, I click the “Preview” tab.

要以“预览”模式启动报告,请单击“预览”选项卡。

The report screen comes up.

报告屏幕出现。

Note that all that is present are our “Market Value” and “Fund Reference” ‘buttons’ to the left, the SQL Shack logo and the “SQL Shack Financial Dashboard” report title. Why are these the only items visible? The reason being that the visibility properties on these items WERE NOT SET, therefore they are visible.

请注意,此处显示的全部是我们左侧的“市场价值”和“资金参考”“按钮”,SQL Shack徽标以及“ SQL Shack Financial Dashboard”报告标题。 为什么只有这些项目可见? 原因是未设置这些项目的可见性属性, 因此它们是可见的

By clicking on the “Market Value” text box, we see the following

通过点击“市场价值”文本框,我们看到以下内容

and by clicking the “Fund Reference” text box we note the following:

通过单击“资金参考”文本框,我们注意到以下内容:

This said, we have taken a complex report and broken it up into two proper ‘logical units’, we have saved valuable real estate and all within one physical report!

这就是说,我们已经采取了一份复杂的报告,并将其分解为两个适当的“逻辑单元”,我们节省了宝贵的房地产,并且全部都保存在一份物理报告中!

结论 (Conclusions)

Creating reports utilizing SQL Server Reporting Services is often complex due to end user requirements. Often users wish to view excessive amounts of data on limited amounts of ‘real estate’ within the report body.

由于最终用户的要求,使用SQL Server Reporting Services创建报告通常很复杂。 通常,用户希望在报告正文中查看有关有限数量“房地产”的过多数据。

By breaking the report down into logical units and working with the “visibility” property of the ‘containing’ rectangles we were able to remove much of the complexity, by enabling the user to define what he or she currently wishes to view; based upon selection “buttons” / text boxes.

通过将报告分解为逻辑单元并使用“包含”矩形的“可见性”属性,我们使用户能够定义他或她当前希望查看的内容,从而消除了很多复杂性。 根据选择的“按钮” /文本框。

As always should you have any questions pertaining to what I have just covered or should you wish a copy of the SQL Server Data Tools project, please feel free to contact me.

与往常一样,如果您对我刚刚介绍的内容有任何疑问,或者希望复制SQL Server数据工具项目,请随时与我联系。

In the interim, happy programming.

在此期间,编程愉快。

翻译自: https://www.sqlshack.com/reduce-report-complexity-using-visibility-tab-in-ssdt/

如何使用SQL Server数据工具中的“可见性”选项降低报告的复杂性相关推荐

  1. SQL Server商业智能功能– SQL Server数据工具–商业智能

    介绍 (Introduction) 在上一篇有关introduction to SQL Server business intelligence we covered the general stru ...

  2. tfs 文件系统部署_使用SQL Server数据工具和使用自定义工作流文件的TFS部署到多个数据库

    tfs 文件系统部署 In the previous blog post : Deployment to several databases using SQL Server Data Tools a ...

  3. 使用SQL Server数据工具进行SQL单元测试

    This article on SQL Unit Testing is the second part on the series about SSDT and database developmen ...

  4. 使用SQL Server数据工具和Visual Studio Online进行连续部署

    In the previous posts 在以前的帖子中 Deployment to several databases using SQL Server Data Tools and TFS us ...

  5. ssdt_用于商业智能开发SQL Server数据工具(SSDT)的演变

    ssdt By all accounts, the introduction of SQL Server Data Tools (SSDT) in SQL Server 2012 was a wate ...

  6. SQL Server数据表中数据的增加(插入)、查询、修改、删除

    目录 零.码仙励志 一.数据表中数据的增加(插入) 二.数据表中数据的查询 三.数据表中数据的修改 四.数据表中数据的删除 零.码仙励志 伟人所达到并保持着的高处,并不是一飞就到的,而是他们在同伴们都 ...

  7. SQL Server中的报表–使用SQL Server数据工具将三个报表合并为一个报表

    介绍 (Introduction) In our last "fireside chat" we discussed a few of the challenges that th ...

  8. SQL Server安全机制–如何控制用户能够在报告中查看哪些数据

    介绍 ( Introduction ) A few years back, a client asked me to implement a quick and dirty "securit ...

  9. 使用游标正确提取SQL Server数据并将其放置在Reporting Services矩阵中

    介绍 ( Introduction ) In our last two chats, we discussed enterprises that have had financial years th ...

最新文章

  1. VC++ 模拟quot;CLICK事件quot;关闭指定窗体
  2. Spring Boot 2.x基础教程:默认数据源Hikari的配置详解
  3. 03-树3 Tree Traversals Again (c++递归实现)
  4. 好身材大姐姐学计算机惊喜用英语,英语作文:一个大大的惊喜A Big Surprise
  5. Flink SQL 功能解密系列 —— 流式 TopN 挑战与实现
  6. 【kafka】kafka topic某些分区 副本落后leader太多
  7. [收藏] C#面试基础问题
  8. 不敢下水游泳,莫慌!VR带你畅游水底世界
  9. 【无捆绑,可修改主页】系统之家 win7 32位64位极度纯净版系统(每月更新)
  10. C语言---学生奖学金评定系统设计
  11. 高级软件工程第七次作业:LLS战队Alpha敏捷冲刺5
  12. 滴滴拉屎之后是什么?
  13. 【技术思路】极客时间-左耳听风-开篇词1
  14. 人人旗下风车网CEO的创业失败教训总结
  15. BIOMOD2模型、MaxEnt模型物种分布模拟,生物多样性生境模拟,论文写作
  16. BMP与JPG图片格式的互相转换
  17. CAD偏移曲线(com接口c#语言)
  18. 斯德哥尔摩的照片七:城市漫步(中)
  19. 设置 SSH 通过密钥登录
  20. 我惟一的能说话的地盘回来了

热门文章

  1. C# 关键字 virtual、override和new的用法
  2. mysql 42
  3. IntelliJ IDEA 2017 MySQL5 绿色版 Spring 4 Mybatis 3 配置步骤详解(二)
  4. word插入图片被文字挡住问题
  5. 条款34:区分接口继承和实现继承(Different between inheritance of interface and inheritance of implemenation)...
  6. Eclipse启动Tomcat时45秒超时的解决方法
  7. Android之提交数据到服务端方法简单封装
  8. ★LeetCode(669)——修剪二叉搜索树(JavaScript)
  9. 句句真研—每日长难句打卡Day7
  10. winccweb发布画面不显示_wincc web navigator 发布用户名或密码错误问题