I\'m trying to select from XML that has a null as one of the attributes. Instead of returning a null, it returns a 0. What am I doing wrong?
See code below to replicate:>
I'm not sure if your particular case requires you to sub-query the nodes first, but if not you can request the .value and provide the xPath. Since the Property1 node exists, you want to evaluate the text() of the Property1 node and not the node itself:
select ParamValues.TaskChainerTask.value('Property1[1]/text()[1]','int') as Property1,
ParamValues.TaskChainerTask.value('Property2[1]/text()[1]','int') as Property2
from @a.nodes('(/TestSet/Element)') as ParamValues(TaskChainerTask)
In addition to make sure this works in other cases you can provide the most detailed element path in the @a.nodes xPath statment and walk up with "../" instead of sub-querying the node results.