Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing nodes() method in SQL Server 2008 RC2

I'm trying to query using a XPath expression. My Microsoft SQL Server 2008 RC2 knows the functions value() and query() but is missing the nodes() method.

Example:

SELECT Data.nodes('/root/ids/id') As id FROM myTable

Data is a XML column in the table myTable.

Is it required to install the nodes() method somehow?

like image 818
Rico Suter Avatar asked Jul 16 '12 11:07

Rico Suter


1 Answers

nodes can return more than one row so you don't call it as though it returns a scalar

with myTable as
(
SELECT CAST('<root><ids><id>1</id><id>2</id></ids></root>' AS XML) AS Data
)

SELECT x.value('.', 'int')
FROM   myTable
       CROSS APPLY Data.nodes('/root/ids/id') x(x)
like image 57
Martin Smith Avatar answered Sep 28 '22 18:09

Martin Smith