鉴于以下XPath CTE,我想在Field2
上进行过滤。怎么能实现呢?我只是学习XPath。使用SQL Server 2008 R2。
WITH ConvertedToXML AS
(
SELECT TOP 10
xml_msg AS AsVarchar,
CAST(xml_msg AS XML) AS AsXml
FROM
Table
ORDER BY
date_received desc
)
SELECT
ConvertedToXML.AsXml.value('(//Field1)[1]', 'varchar(max)') AS Field1,
ConvertedToXML.AsXml.value('(//Field2)[1]', 'Varchar(10)') as Field2,
ConvertedToXML.AsVarchar,
ConvertedToXML.AsXml
Into #TempXML
FROM ConvertedToXML;
答案 0 :(得分:1)
如果我正确理解了这个问题,您希望过滤Field2
值等于某个值foo
的行,例如,您可以这样做:
SELECT
......
......
Into #TempXML
FROM ConvertedToXML
WHERE ConvertedToXML.AsXml.value('(//Field2)[1]', 'Varchar(10)') = 'foo';
或者使用XPath谓词来获取值等于Field2
的{{1}}个元素,并使用exists()
方法执行XPath:
"foo"