Is there a way to check that value of an element in the XML field has an empty size using SQLXML? Consider I have the following data in the column Conf
of the table Test
:
<Conf>
<UserData>
<data type="str" value="" />
</UserData>
</Conf>
I can check that data
exists by using the following SQL request:
SELECT Test.Conf.exist('/Conf/UserData/data') FROM Test;
But how can I check that data
has an empty value
? It could be something like the following, but it doesn't work:
SELECT Test.Conf.value('(/Conf/UserData/data/@value)[1]', 'nvarchar(max)')='' FROM Test;
My final solution is to use the following SQL statement:
SELECT Test.Conf.value('string-length(/Conf[1]/UserData[1]/data[1]/@value)', 'int') FROM Test;
Using XPath 1.0. string(@someattribute)
test should return false if empty. I know nothing about SQLXML, but it will work if you can use a control sequence.