Skip to content
Advertisement

Filter an XML column in SQL Server

I have an xml type column productsXML in product table

I want to find all the rows that have <products></products>.

I tried this:

This is returning all the rows that have products tag and understandably so.

Is there a way to filter only those rows that have <products></products>?

Advertisement

Answer

PLease try the following solution.

It is checking that the root products element has no child elements.

SQL

Output

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement