【问题标题】:Find SSRS subscriptions that never ran successful in the past 30 days?查找过去 30 天内从未成功运行的 SSRS 订阅?
【发布时间】:2021-12-08 14:12:23
【问题描述】:

我正在尝试编写 SQL 选择语句来查找在过去 30 天内从未成功运行过的 SSRS 订阅,以便我可以禁用这些订阅。

有人知道怎么做吗?由于每次作业运行时执行日志都会创建唯一记录,因此我试图按报告路径对它们进行分组,但被困在那里。有人可以帮我吗?

我的想法是这样的:

SELECT ItemPath
FROM [ReportServer].dbo.ExecutionLog3 EX
GROUP BY ItemPath, Status, TimeEnd
HAVING Ex.TimeEnd >= DATEADD(day, -30, GETDATE())
   AND Status != 'rsSuccess'

【问题讨论】:

  • 为什么你的子句在HAVING而不是WHERE
  • 因为我要查找过去 30 天内从未成功运行过的报告。如果我不将它们分组,我如何才能知道它们在过去 30 天内是否随着时间的推移不断失败并且它们从未成功运行。如果它在过去 30 天内成功运行一次,我不想在结果中看到那些 ItemPath 。这是一个更新的想法: SELECT P.ItemPath, COUNT(*) FROM ( SELECT * FROM [ReportServer].dbo.ExecutionLog3 EX WHERE Ex.TimeEnd >= DATEADD(day, -30, GETDATE())) P GROUP BY P。 ItemPath,P.Status HAVING Status != 'rsSuccess'
  • 但是HAVING 中的子句都没有使用聚合,那么为什么它们在那里而不在WHERE 中? HAVING 子句用于与聚合值进行比较时。喜欢HAVING SUM(Price) > 1000
  • 如果订阅在过去 30 天内根本没有运行会怎样?
  • 执行日志只显示运行的订阅,我最终会写一个存储过程来禁用那些在过去 30 天内总是失败的订阅。

标签: sql sql-server reporting-services


【解决方案1】:

这里有一个算法可以帮助你:

With
Subscriptions As
(
    Select SubscriptionId, SubscriptionName
    From dbo.TableOfSubscriptions
)
, Executions As
(
    Select SubscriptionId, ExecutionStatus, Count (*) NumExecutions
    From dbo.TableOfExecutions
    Group By SubscriptionId, ExecutionStatus
)
, SubscriptionsExecutions As
(
    Select 
        SubscriptionId, SubscriptionName
        , IsNull((Select Sum (NumExecutions) From Executions Where ExeuctionStatus = 'Failed'), 0) ExecutionFailed
        , IsNull((Select Sum (NumExecutions) From Executions Where ExeuctionStatus = 'Success'), 0) ExecutionSuccessful
    From Subscriptions
)
Select *
From SubscriptionsExecutions
Where ExecutionSuccessful = 0
and ExecutionFailed <> 0

【讨论】:

  • 感谢回复,但无法得到我想要的结果。
  • 你遇到了什么问题?
猜你喜欢
  • 2020-06-29
  • 1970-01-01
  • 2011-07-07
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-01
相关资源
最近更新 更多