Dixie Normous wrote:
> For example, say I have the following XML:
>
> .... [parentNode]
>
> ........ [test1][/test1]
> ........ [test2][/test2]
>
> ........ [subNode]
> ............ [subTest1]123[/subTest1]
> ............ [subTest2]234[/subTest2]
> ........ [/subNode]
>
> .... [/parentNode]
>
> Once I load the XML into a variable, there will be instances when
> [subNode] may or may not exist. What's a straightforward method to
> detect whether [subNode] is present?
There is a method named exist on the XML data type:
DECLARE @x XML;
SET @x = N'<parentNode>
<test1></test1>
<test2></test2>
<subNode>
<subTest1>123</subTest1>
<subTest2>234</subTest2>
</subNode>
</parentNode>';
SELECT @x.exist('/parentNode/subNode');
You can pass in any XPath so for instance if you wanted to check there
is a 'subNode' element at any level you would use
SELECT @x.exist('//subNode');
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
>> Stay informed about: SQL 2005, is there a way to determine whether a specific n..