Selecting null value from XML in SQL Server

前端 未结 8 1939
Happy的楠姐
Happy的楠姐 2021-02-19 20:23

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:

8条回答
  •  没有蜡笔的小新
    2021-02-19 20:52

    I think if you use the number() function, you'll get null as expected. This only works for number types though:

    select 
       ParamValues.TaskChainerTask.query('Property1').value('number(.)','int') as Property1,         
       ParamValues.TaskChainerTask.query('Property2').value('number(.)','int') as Property2
    from @a.nodes('(/TestSet/Element)') as ParamValues(TaskChainerTask) 
    

提交回复
热议问题