简体   繁体   English

数据驱动订阅 SSRS 标准版 2008

[英]Data Driven Subscriptions SSRS Standard Edition 2008

I'm fairly new to MSSQL and SSRS.我对 MSSQL 和 SSRS 还很陌生。

I'm trying to create a data driven subscription in MSSQL 2008 Standard SSRS that does the following.我正在尝试在执行以下操作的 MSSQL 2008 标准 SSRS 中创建数据驱动订阅。

Email the results of the report to a email address found within the report.将报告结果通过电子邮件发送到报告中找到的电子邮件地址。 Run Daily每天跑步

For Example:例如:

Select full_name, email_address from users where (full_name = 'Mark Price')

This would use the email_address column to figure out who to email, This must also work for multiple results with multiple email address's.这将使用 email_address 列来确定向谁发送电子邮件,这也必须适用于具有多个电子邮件地址的多个结果。

The way I'm thinking of doing this is making a subscription to run the query, if no result is found then nothing happens.我正在考虑这样做的方式是订阅运行查询,如果没有找到结果,那么什么也不会发生。 But if a result is found then the report changes the row in Subscriptions table to run the report again in the next minute or so with the correct email information found in the results.但是,如果找到结果,则报告会更改订阅表中的行,以在下一分钟左右再次运行报告,并在结果中找到正确的电子邮件信息。 Is this a silly idea or not?这是一个愚蠢的想法吗?

I've found a couple blog posts claiming this works but i couldn't understand their code enough to know what it does.我发现了几篇博文声称这是有效的,但我无法理解他们的代码,无法知道它的作用。

So, Any suggestions on how to go about this or if you can suggest something already out there on the internet with a brief description?那么,关于如何解决这个问题的任何建议,或者您是否可以建议一些已经在互联网上提供的简短描述?

I've implemented something like this on SQL Server Standard to avoid having to pay for Enterprise.我已经在 SQL Server Standard 上实现了这样的东西,以避免为 Enterprise 付费。 First, I built a report called “Schedule a DDR” (Data Driven Report).首先,我构建了一个名为“Schedule a DDR”(数据驱动报告)的报告。 That report has these parameters:该报告具有以下参数:

Report to schedule: the name of the SSRS report (including folder) that you want to trigger if the data test is met.要计划的报告:满足数据测试时要触发的 SSRS 报告(包括文件夹)的名称。 Eg "/Accounting/Report1".例如“/Accounting/Report1”。

Parameter set: a string that will be used to look up the parameters to use in the report.参数集:将用于查找要在报告中使用的参数的字符串。 Eg "ABC".例如“ABC”。

Query to check if report should be run: a SQL query that will return a single value, either zero or non-zero.检查是否应运行报告的查询:将返回单个值(零或非零)的 SQL 查询。 Zero will be interpreted as "do not run this report"零将被解释为“不运行此报告”

Email recipients: a list of semicolon-separated email recipients that will receive the report, if it is run.电子邮件收件人:以分号分隔的电子邮件收件人列表,这些收件人将收到报告(如果运行)。

Note that the “Schedule a DDR” report is the report we're actually running here, and it will send its output to me;请注意,“安排 DDR”报告是我们在此处实际运行的报告,它会将其输出发送给我; what it does is run another report – in this case it's “/Accounting/Report1” and it's that report that needs these email addresses.它的作用是运行另一个报告——在本例中它是“/Accounting/Report1”,它是需要这些电子邮件地址的报告。 So “Schedule a DDR” isn't really a report, although it's scheduled and runs like one – it's a gadget to build and run a report.因此,“计划 DDR”并不是真正的报告,尽管它是按计划进行并运行的——它是一个构建和运行报告的小工具。

I also have a table in SQL defined as follows:我在 SQL 中还有一个表定义如下:

CREATE TABLE [dbo].[ParameterSet](
            [ID] [varchar](50) NULL,
            [ParameterName] [varchar](50) NULL,
            [Value] [varchar](2000) NULL
) ON [PRIMARY]

Each parameter set – "ABC" in this case – has a set of records in the table.每个参数集——在本例中为“ABC”——在表中都有一组记录。 In this case the records might be ABC/placecode/AA and ABC/year/2013, meaning that there are two parameters in ABC: placecode and year, and they have values "AA" and "2013".在这种情况下,记录可能是 ABC/placecode/AA 和 ABC/year/2013,这意味着 ABC 中有两个参数:placecode 和 year,它们的值分别为“AA”和“2013”​​。

The dataset for the "Schedule a DDR" report in SSRS is SSRS 中“安排 DDR”报告的数据集是

DDR.dbo.DDR3 @reportName, @parameterSet, @nonZeroQuery, @toEmail;

DDR3 is a stored procedure: DDR3 是一个存储过程:

CREATE PROCEDURE [dbo].[DDR3] 
   @reportName            nvarchar(200),
   @parameterSet   nvarchar(200),
   @nonZeroQuery   nvarchar(2000),
   @toEmail        nvarchar(2000)
AS
BEGIN
   -- SET NOCOUNT ON added to prevent extra result sets from
   -- interfering with SELECT statements.
   SET NOCOUNT ON;

   select ddr.dbo.RunADDR(@reportName,@parameterSet,@nonZeroQuery,@toEmail) as DDRresult;

   END

RunADDR is a CLR. RunADDR 是一个 CLR。 Here's an outline of how it works;这是它如何工作的概述; I can post some code if anyone wants it.如果有人需要,我可以发布一些代码。

  • Set up credentials设置凭据
  • Select all the parameters in the ParameterSet table where the parameterSet field matches the parameter set name passed in from the Schedule A DDR report选择 ParameterSet 表中的所有参数,其中 parameterSet 字段与从 Schedule A DDR 报告传入的参数集名称匹配
  • For each of those parameters对于每个参数
    • Set up the parameters array to hold the parameters defined in the retrieved rows.设置参数数组以保存在检索到的行中定义的参数。 (This is how you use the table to fill in parameters dynamically.) (这就是您使用表格动态填充参数的方式。)
  • End for结束于
  • If there's a “nonZeroQuery” value passed in from Schedule A DDR如果有从 Schedule A DDR 传入的“nonZeroQuery”值
    • Then run the nonZeroQuery and exit if you got zero rows back.然后运行 ​​nonZeroQuery 并在返回零行时退出。 (This is how you prevent query execution if some condition is not met; any query that returns something other zero will allow the report to run) (这是在不满足某些条件时阻止查询执行的方法;任何返回其他零值的查询都将允许报告运行)
  • End if万一
  • Now ask SSRS to run the report, using the parameters we just extracted from the table, and the report name passed in from Schedule A DDR现在让 SSRS 运行报告,使用我们刚刚从表中提取的参数,以及从 Schedule A DDR 传入的报告名称
  • Get the output and write it to a local file获取输出并将其写入本地文件
  • Email the file to whatever email addresses were passed in from Schedule A DDR将文件通过电子邮件发送到从 Schedule A DDR 传入的任何电子邮件地址

This takes me back to my old job where I wrote a solution to a problem using data-driven subscriptions on our SQL Server 2005 Enterprise development box and then discovered to my dismay that our customer only had Standard.这让我回到了我的旧工作,在那里我使用 SQL Server 2005 Enterprise 开发盒上的数据驱动订阅编写了一个问题的解决方案,然后我沮丧地发现我们的客户只有标准版。

I bookmarked this post at the time and it looked very promising, but I ended up moving jobs before I had a chance to implement it.我当时为这篇文章添加了书签,它看起来非常有前途,但在我有机会实施它之前,我最终换了工作。

Of course, it is targeted at 2005, but one of the comments seems to suggest it works in 2008 as well.当然,它是针对 2005 年的,但其中一条评论似乎表明它在 2008 年也有效。

R-Tag支持 SQL Server 标准版的 SSRS 数据驱动报告

Instead of creating a subscription to modify the subscriptions table, I would put that piece somewhere else, such as in a SQL agent.我不会创建订阅来修改订阅表,而是将该部分放在其他地方,例如在 SQL 代理中。 But the idea is the same.但想法是一样的。 A regularly running piece of SQL can add or change lines in the subscription table.一条定期运行的 SQL 可以在订阅表中添加或更改行。

A Google of "SSRS Subscription table" returned a few helpful results: Here's an article based on 2005, but the principles should be the same for 2008: This article is for 2008, and is really close to what you are describing as well.一个“SSRS订阅表”的谷歌返回了一些有用的结果: 这是一篇基于2005年的文章,但2008年的原则应该是一样的: 这篇文章是针对2008年的,也非常接近您所描述的。

I would just look at the fields one by one in the subscriptions table and determine what you need for each.我只会一一查看订阅表中的字段,并确定每个字段需要什么。 Try creating a row by hand (a manual insert statement) to send yourself a subscription.尝试手动创建一行(手动插入语句)以向自己发送订阅。

You can use SQL-RD, a third-party solution, to create and run data-driven schedules without having to upgrade to SQL enterprise.您可以使用第三方解决方案 SQL-RD 来创建和运行数据驱动的计划,而无需升级到 SQL 企业。 It also comes with event-based scheduling (triggers the report on events including database changes, file changes, emails received and so on).它还带有基于事件的调度(触发事件报告,包括数据库更改、文件更改、收到的电子邮件等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM