s-s-rS 订阅 - 如何查看所有报告收件人

Posted

技术标签:

【中文标题】s-s-rS 订阅 - 如何查看所有报告收件人【英文标题】:s-s-rS Subscriptions - How to view ALL report recipients 【发布时间】:2013-09-28 10:48:49 【问题描述】:

我编写了一份 s-s-rS 报告来帮助我跟踪 s-s-rS 订阅。我改变了一个脚本的用途,该脚本将使用 Reportserver.dbo.Subscriptions.LastStatus 来查看电子邮件收件人,但是,它只会列出 LastStatus 的前 520 个字符。因为我们的一些分发列表非常大,所以找不到我的脚本搜索的某些名称(即使它们是分发的一部分)。以下是我正在使用的脚本:

SELECT Reportname = c.Name 
  ,FileLocation = c.Path
  ,SubscriptionDesc=su.Description 
  ,Subscriptiontype=su.EventType 
  ,su.LastStatus 
  ,su.LastRunTime 
  ,Schedulename=sch.Name 
  ,ScheduleType = sch.EventType 
  ,ScheduleFrequency = 
   CASE sch.RecurrenceType 
   WHEN 1 THEN 'Once' 
   WHEN 2 THEN 'Hourly' 
   WHEN 4 THEN 'Daily/Weekly' 
   WHEN 5 THEN 'Monthly' 
   END 
  ,su.Parameters 
  FROM Reportserver.dbo.Subscriptions su 
  JOIN Reportserver.dbo.Catalog c 
    ON su.Report_OID = c.ItemID 
  JOIN Reportserver.dbo.ReportSchedule rsc 
    ON rsc.ReportID = c.ItemID 
   AND rsc.SubscriptionID = su.SubscriptionID 
  JOIN Reportserver.dbo.Schedule Sch 
    ON rsc.ScheduleID = sch.ScheduleID 
WHERE  LastStatus like @Email
ORDER BY LastRunTime DESC

我在网上找到的任何代码都使用 LastStatus 列来显示此数据。如果有人对我列出报告分发列表的所有成员的更完整方式有任何建议,我将不胜感激。

【问题讨论】:

【参考方案1】:

下面是查询订阅参数全文的SQL。我认为这适用于极长的地址列表,但我目前没有可用的带有长地址列表的测试服务器。

如果在生产中使用它,我可能会添加几个 WITH ( NOLOCK ),并且不会期望 MS 支持解决问题。

   ;
   WITH subscriptionXmL
          AS (
               SELECT
                SubscriptionID ,
                OwnerID ,
                Report_OID ,
                Locale ,
                InactiveFlags ,
                ExtensionSettings ,
                CONVERT(XML, ExtensionSettings) AS ExtensionSettingsXML ,
                ModifiedByID ,
                ModifiedDate ,
                Description ,
                LastStatus ,
                EventType ,
                MatchData ,
                LastRunTime ,
                Parameters ,
                DeliveryExtension ,
                Version
               FROM
                ReportServer.dbo.Subscriptions
             ),
                 -- Get the settings as pairs
        SettingsCTE
          AS (
               SELECT
                SubscriptionID ,
                ExtensionSettings ,
    -- include other fields if you need them.
                ISNULL(Settings.value('(./*:Name/text())[1]', 'nvarchar(1024)'),
                       'Value') AS SettingName ,
                Settings.value('(./*:Value/text())[1]', 'nvarchar(max)') AS SettingValue
               FROM
                subscriptionXmL
                CROSS APPLY subscriptionXmL.ExtensionSettingsXML.nodes('//*:ParameterValue') Queries ( Settings )
             )
    SELECT
        *
    FROM
        SettingsCTE
    WHERE
        settingName IN ( 'TO', 'CC', 'BCC' )

【讨论】:

这正是我想要的!搜索 TO 和 CC 的能力非常完美,因为我希望接下来修复报告的那部分。很不错的剧本!感谢您的帮助杰米 这太棒了。但是,我如何批量更新电子邮件地址?用例是一位前员工将其公司电子邮件地址放入报告中。【参考方案2】:

我还从SQL Server MSDN Social 中找到了这个查询; 原始查询作者 MSDN 简介:Sandip Shinde

SELECT
c.Name AS ReportName,
'Next Run Date' = CASE next_run_date
WHEN 0 THEN null
ELSE
substring(convert(varchar(15),next_run_date),1,4) + '/' +
substring(convert(varchar(15),next_run_date),5,2) + '/' +
substring(convert(varchar(15),next_run_date),7,2)
END,
'Next Run Time' = isnull(CASE len(next_run_time)
WHEN 3 THEN cast('00:0'
+ Left(right(next_run_time,3),1)
+':' + right(next_run_time,2) as char (8))
WHEN 4 THEN cast('00:'
+ Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
WHEN 5 THEN cast('0' + Left(right(next_run_time,5),1)
+':' + Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
WHEN 6 THEN cast(Left(right(next_run_time,6),2)
+':' + Left(right(next_run_time,4),2)
+':' + right(next_run_time,2) as char (8))
END,'NA'),
Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="TO"])[1]','nvarchar(50)') as [To]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="CC"])[1]','nvarchar(50)') as [CC]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="RenderFormat"])[1]','nvarchar(50)') as [Render Format]
,Convert(XML,[ExtensionSettings]).value('(//ParameterValue/Value[../Name="Subject"])[1]','nvarchar(50)') as [Subject]
---Example report parameters: StartDateMacro, EndDateMacro & Currency.
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="StartDateMacro"])[1]','nvarchar(50)') as [Start Date]
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="EndDateMacro"])[1]','nvarchar(50)') as [End Date]
,Convert(XML,[Parameters]).value('(//ParameterValue/Value[../Name="Currency"])[1]','nvarchar(50)') as [Currency]
,[LastStatus]
,[EventType]
,[LastRunTime]
,[DeliveryExtension]
,[Version]
FROM 
 dbo.[Catalog] c
INNER JOIN dbo.[Subscriptions] S ON c.ItemID = S.Report_OID
INNER JOIN dbo.ReportSchedule R ON S.SubscriptionID = R.SubscriptionID
INNER JOIN msdb.dbo.sysjobs J ON Convert(nvarchar(128),R.ScheduleID) = J.name
INNER JOIN msdb.dbo.sysjobschedules JS ON J.job_id = JS.job_id

【讨论】:

以上是关于s-s-rS 订阅 - 如何查看所有报告收件人的主要内容,如果未能解决你的问题,请参考以下文章

s-s-rS 2008 报告订阅电子邮件随机接收传递扩展加载错误

报告订阅 s-s-rS 中的电子邮件传递

多个用户的 s-s-rS 报告[关闭]

如何将具有链接报告的 s-s-rS 报告导出到 Excel

s-s-rS 订阅电子邮件组(分发列表)不起作用

s-s-rS 中的自定义定时订阅计划