Sql 如何使用exist和contains查询RDL XML数据?
问题: 我接着介绍了如何查询ReportServer数据库SQL Server Reporting Services以返回XML结果。我的TSQL中的最后一行在我知道它应该是真的时候却不是真的 WHERE子句应该检查ContextXML节点中单词Select的文本。我知道Select在文本中,但WHERE子句的计算结果不是真的 这是我的问题最后一行是问题: 请发布您的ContentXML数据示例请发布您的ContentXML数据示例Sql 如何使用exist和contains查询RDL XML数据?,sql,sql-server,tsql,xpath,xquery,Sql,Sql Server,Tsql,Xpath,Xquery,问题: 我接着介绍了如何查询ReportServer数据库SQL Server Reporting Services以返回XML结果。我的TSQL中的最后一行在我知道它应该是真的时候却不是真的 WHERE子句应该检查ContextXML节点中单词Select的文本。我知道Select在文本中,但WHERE子句的计算结果不是真的 这是我的问题最后一行是问题: 请发布您的ContentXML数据示例请发布您的ContentXML数据示例 --The first CTE gets the conten
--The first CTE gets the content as a varbinary(max)
--as well as the other important columns for all reports,
--data sources and shared datasets.
WITH ItemContentBinaries AS
(
SELECT
ItemID,Name,[Type]
,CASE Type
WHEN 2 THEN 'Report'
WHEN 5 THEN 'Data Source'
WHEN 7 THEN 'Report Part'
WHEN 8 THEN 'Shared Dataset'
ELSE 'Other'
END AS TypeDescription
,CONVERT(varbinary(max),Content) AS Content
FROM ReportServer.dbo.Catalog
WHERE Type IN (2)
and ItemID = '19EE23BD-E752-4021-A533-7CF159D2DB7A' -- <-- This is a RDL that I know has "Select" in its CommandText node.
),
--The second CTE strips off the BOM if it exists...
ItemContentNoBOM AS
(
SELECT
ItemID,Name,[Type],TypeDescription
,CASE
WHEN LEFT(Content,3) = 0xEFBBBF
THEN CONVERT(varbinary(max),SUBSTRING(Content,4,LEN(Content)))
ELSE
Content
END AS Content
FROM ItemContentBinaries
)
--The old outer query is now a CTE to get the content in its xml form only...
,ItemContentXML AS
(
SELECT
ItemID,Name,[Type],TypeDescription
,CONVERT(xml,Content) AS ContentXML
FROM ItemContentNoBOM
)
-- Now filter items having containing the word "select" in their CommandText node.
SELECT
ItemID,
Name,
[Type],
TypeDescription,
ContentXML
FROM
ItemContentXML
WHERE
ContentXML.exist('//CommandText[contains(.,"Select")]') = 1; -- <-- THE PROBLEM! This isn't evaluating to true, even though the RDL I'm querying has "Select" in its CommandText text.