如何从 ReportServerXML 中提取订阅优先级?

How can I extract subscription priority from ReportServerXML?

我在 SQL Server 2014 和 Microsoft 开箱即用的 ReportServer 数据库中工作。由于这个 bug.

,我一直在创建一个脚本来提取订阅优先级

我使用以下查询编写了以下查询:SQL、XQuery 和 XPath。

;WITH XMLNAMESPACES (DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition','http://schemas.microsoft.com/SQLServer/reporting/reportdesigner' AS rd )
,s
as (SELECT  
      s.Report_OID
     ,s.SubscriptionID
     ,s.OwnerID
     ,s.Description 
     ,s.LastStatus
     ,s.EventType
     ,CONVERT(XML,CONVERT(VARCHAR(MAX),s.ExtensionSettings)) AS reportXML
    FROM ReportServer.dbo.Subscriptions as s
    WHERE s.ExtensionSettings is not null
   )
--SELECT s.reportxml.value('/ParameterValues[1]','varchar(150)') FROM s

SELECT 
 con.Report_OID
,con.test
FROM (SELECT 
       s.Report_OID
      ,dsn.value('Name[1]','varchar(150)') as test
      FROM s
      cross apply reportxml.nodes('/ParameterValues/ParameterValue')  as r(dsn)
     ) con

我还有 2 个示例 xml 文档粘贴在下面。

   <ParameterValues>
      <ParameterValue>
        <Name>FILENAME</Name>
        <Field>subscriber_domestic_id</Field>
      </ParameterValue>
      <ParameterValue>
        <Name>PATH</Name>
        <Field>folder</Field>
      </ParameterValue>
      <ParameterValue>
        <Name>RENDER_FORMAT</Name>
        <Value>PDF</Value>
      </ParameterValue>
      <ParameterValue>
        <Name>WRITEMODE</Name>
        <Value>OverWrite</Value>
      </ParameterValue>
      <ParameterValue>
        <Name>FILEEXTN</Name>
        <Value>True</Value>
      </ParameterValue>
      <ParameterValue>
        <Name>USERNAME</Name>
        <Field>login</Field>
      </ParameterValue>
      <ParameterValue>
        <Name>PASSWORD</Name>
        <Field>mypasswordstackOF</Field>
      </ParameterValue>
    </ParameterValues>

The second document here.

<ParameterValues>
  <ParameterValue>
    <Name>TO</Name>
    <Value>jonjones@email.com;billiejean@email.com;prettyfloyd@email.com</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>CC</Name>
    <Value>a@email.com;g@email.com.com;</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>IncludeReport</Name>
    <Value>True</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>RenderFormat</Name>
    <Value>PDF</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>Subject</Name>
    <Value>@ReportName was executed at @ExecutionTime</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>IncludeLink</Name>
    <Value>True</Value>
  </ParameterValue>
  <ParameterValue>
    <Name>Priority</Name>
    <Value>NORMAL</Value>
  </ParameterValue>
</ParameterValues>

由此可见,并非所有文件都有优先级。我当前的查询没有出错,但没有 return 任何内容。我相信我正确使用了 nodes() 函数。关于如何正确处理这个问题的任何想法?

为了将来的目的,如果有人想要完成相同类型的提取,我将我的代码粘贴在下面:

;WITH
s
as (SELECT  
      s.Report_OID
     ,s.SubscriptionID
     ,s.OwnerID
     ,s.Description 
     ,s.LastStatus
     ,s.EventType
     ,CONVERT(XML,CONVERT(VARCHAR(MAX),s.ExtensionSettings)) AS reportXML
    FROM ReportServer.dbo.Subscriptions as s (NOLOCK)
    WHERE s.ExtensionSettings is not null
   )

SELECT 
 con.Report_OID
,con.Node
,con.PriorityLevel
INTO #Temp
FROM (SELECT 
       s.Report_OID
      ,dsn.value('Name[1]','varchar(150)') as Node
      ,dsn.value('Value[1]','varchar(150)') as PriorityLevel
      FROM s
      cross apply reportxml.nodes('/ParameterValues/ParameterValue')  as r(dsn)
     ) con

SELECT 
 t.Report_OID
,c.Name as 'ReportName'
,t.Node
,t.PriorityLevel
,c.Path
FROM #Temp t
    join ReportServer.dbo.Catalog c (NOLOCK)
        on t.Report_OID = c.ItemID 
WHERE 1=1 
and Node = 'Priority'

尽情享受吧!