数据驱动订阅 SSRS 标准版 2008

发布于 2024-12-11 20:52:42 字数 524 浏览 0 评论 0原文

我对 MSSQL 和 SSRS 相当陌生。

我正在尝试在 MSSQL 2008 标准 SSRS 中创建数据驱动的订阅,该订阅执行以下操作。

将报告结果通过电子邮件发送到报告中找到的电子邮件地址。 每天运行

例如,

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

:这将使用 email_address 列来确定向谁发送电子邮件,这也必须适用于具有多个电子邮件地址的多个结果。

我考虑这样做的方法是订阅来运行查询,如果没有找到结果,那么什么也不会发生。 但是,如果找到结果,则报告会更改订阅表中的行,以便在下一分钟左右再次运行报告,并在结果中找到正确的电子邮件信息。 这是一个愚蠢的想法吗?

我发现了几篇博客文章声称这有效,但我无法充分理解他们的代码,无法知道它的作用。

那么,关于如何解决这个问题有什么建议吗?或者您是否可以建议互联网上已有的内容并附上简短的描述?

I'm fairly new to MSSQL and SSRS.

I'm trying to create a data driven subscription in MSSQL 2008 Standard SSRS that does the following.

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

放低过去 2024-12-18 20:52:42

这让我回到了以前的工作,当时我在 SQL Server 2005 Enterprise 开发盒上使用数据驱动订阅编写了一个问题的解决方案,然后我沮丧地发现我们的客户只有 Standard。

我添加了书签 这篇文章当时看起来非常有前途,但在我有机会实现它之前我最终就换了工作。

当然,它的目标是 2005 年,但其中一条评论似乎表明它也适用于 2008 年。

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.

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.

吃兔兔 2024-12-18 20:52:42

我已经在 SQL Server Standard 上实现了类似的功能,以避免为 Enterprise 付费。首先,我构建了一个名为“安排 DDR”(数据驱动报告)的报告。该报告具有以下参数:

要计划的报告:满足数据测试时要触发的 SSRS 报告(包括文件夹)的名称。例如“/会计/报告1”。

参数集:用于查找要在报告中使用的参数的字符串。例如“ABC”。

用于检查是否应运行报告的查询:将返回单个值(零或非零)的 SQL 查询。零将被解释为“不运行此报告”

电子邮件收件人:将接收报告(如果运行)的以分号分隔的电子邮件收件人列表。

请注意,“Schedule a DDR”报告是我们实际在此处运行的报告,它会将其输出发送给我;它的作用是运行另一个报告 - 在本例中为“/Accounting/Report1”,并且该报告需要这些电子邮件地址。因此,“安排 DDR”并不是真正的报告,尽管它的计划和运行方式与报告类似 - 它是一个用于构建和运行报告的小工具。

我还在 SQL 中定义了一个表,如下所示:

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

每个参数集(本例中为“ABC”)在表中都有一组记录。在本例中,记录可能是 ABC/placecode/AA 和 ABC/year/2013,这意味着 ABC 中有两个参数:placecode 和year,它们的值为“AA”和“2013”​​。

SSRS 中“安排 DDR”报告的数据集是

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

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 是一个 CLR。以下是其工作原理的概述;如果有人需要,我可以发布一些代码。

  • 设置凭据
  • 选择 ParameterSet 表中的所有参数,其中参数集字段与从 Schedule A DDR 报告传入的参数集名称相匹配
  • 对于每个参数
    • 设置参数数组以保存检索到的行中定义的参数。 (这就是使用表格动态填充参数的方式。)
  • End for
  • 如果有从 Schedule A DDR 传入的“nonZeroQuery”值
    • 然后运行 ​​nonZeroQuery,如果返回零行则退出。 (这是在不满足某些条件时阻止查询执行的方法;任何返回其他零值的查询都将允许报表运行)
  • End if
  • 现在要求 SSRS 使用我们刚刚从表中提取的参数来运行报告,并且从 Schedule A DDR 传入的报告名称
  • 获取输出并将其写入本地文件
  • 通过电子邮件将文件发送到从 Schedule A DDR 传入的任何电子邮件地址

I've implemented something like this on SQL Server Standard to avoid having to pay for Enterprise. First, I built a report called “Schedule a DDR” (Data Driven Report). 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. E.g. "/Accounting/Report1".

Parameter set: a string that will be used to look up the parameters to use in the report. E.g. "ABC".

Query to check if report should be run: a SQL query that will return a single value, either zero or non-zero. 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; what it does is run another report – in this case it’s “/Accounting/Report1” and it’s that report that needs these email addresses. 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.

I also have a table in SQL defined as follows:

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. 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".

The dataset for the "Schedule a DDR" report in SSRS is

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

DDR3 is a stored procedure:

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. 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
  • 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
    • Then run the nonZeroQuery and exit if you got zero rows back. (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
  • Get the output and write it to a local file
  • Email the file to whatever email addresses were passed in from Schedule A DDR
溺孤伤于心 2024-12-18 20:52:42

我不会创建订阅来修改订阅表,而是将该部分放在其他地方,例如 SQL 代理中。但想法是一样的。定期运行的 SQL 可以添加或更改订阅表中的行。

Google 的“SSRS 订阅表”返回了一些有用的结果:这是一篇文章 基于 2005 年,但 2008 年的原则应相同:本文适用于 2008 年,并且也非常接近您所描述的内容。

我只会一一查看订阅表中的字段,并确定每个字段需要什么。尝试手动创建一行(手动插入语句)来向自己发送订阅。

Instead of creating a subscription to modify the subscriptions table, I would put that piece somewhere else, such as in a SQL agent. But the idea is the same. A regularly running piece of SQL can add or change lines in the subscription table.

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.

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.

红衣飘飘貌似仙 2024-12-18 20:52:42

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

R-Tag supports SSRS data driven reports with SQL Server standard edition

迷你仙 2024-12-18 20:52:42

您可以使用第三方解决方案 SQL-RD 创建和运行数据驱动的计划,而无需升级到 SQL Enterprise。它还具有基于事件的调度(触发事件报告,包括数据库更改、文件更改、收到的电子邮件等)。

You can use SQL-RD, a third-party solution, to create and run data-driven schedules without having to upgrade to SQL enterprise. It also comes with event-based scheduling (triggers the report on events including database changes, file changes, emails received and so on).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文