Suppose you are receving XML datatype of message in your stored procedure and you need to extract value from
that xml parameter. Before extracting data you need to check the node is exist or not. Means is that node is empty or not.
You can do it by using the .exist() in MS Sql.
Let me explain using an example.
Suppose we have a @XmlDoc and it contains the ‘
Here in example we are checking is there any Student contains Maths subject. As you can see in our Xml, it is there so it will return 1. Like the
same way we can check the particular node is exist in xml or not. So to check the value, we can use this way.
DECLARE @XmlDoc XML
SET @XmlDoc = ‘
DECLARE @docHandle int
PRINT ‘Maths Exist’
PRINT ‘Maths Not Exist’
PRINT ‘Scienct Exist’
PRINT ‘Science Not Exist’