(SSRS) - 使用XML从[ReportServer]。[dbo]。[Catalog]中提取<autorefresh>值

时间:2015-07-10 16:02:19

标签: sql-server xml reporting-services

我想从<AutoRefresh>0</AutoRefresh>表中提取[ReportServer].[dbo].[Catalog]的值(作为INT)。我知道我可以使用SUBSTRING / CHARINDEX进行一些字符串操作,但我最好使用适当的XML来提取它。

可以在此处找到XML的示例(一旦转换):

http://pastebin.com/S1vWW9BT

有人可以帮忙吗?

以下是将列从VARBINARY获取到XML的代码:

SELECT TOP 13 C.ItemID
    ,C.NAME AS [ReportName]
    ,CONVERT(XML, CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), C.CONTENT))) 
          AS [ReportDeffinitionXML]
FROM [ReportServer].[dbo].[Catalog] AS C WITH (NOLOCK)
WHERE C.Type = 2

1 个答案:

答案 0 :(得分:0)

解决方案由MS员工Shrek Li在以下链接中提供:

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f948ffee-8a3e-4717-b7f7-52e0f280fd4e/ssrs-extracting-autorefresh-value-from-reportserverdbocatalog-with-xml?forum=sqlreportingservices

请注意,需要引用您的相关XML方案:

WITH xmlnamespaces(DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition'),CTE AS(SELECT
   TOP 50
   C.ItemID,
   C.Name AS [ReportName],
   CONVERT(XML, CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), C.CONTENT))) AS [ReportDeffinitionXML] FROM [ReportServer].[dbo].[Catalog] AS C WHERE
   C.Type = 2) SELECT ItemID, [ReportName], [ReportDeffinitionXML], ReportDeffinitionXML].value('(/Report/AutoRefresh)[1]', 'int' ) AS [AutoRefreshValue] FROM CTE