Selecting null value from XML in SQL Server

前端 未结 8 1466
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:53

    In my case, I am using data type boolean so all the answer here doesn't apply to me. If you are using boolean data type, you can try this one:

    myXML.value('Property1[1] cast as xs:boolean?','BIT') AS Property1,
    

    I added this code:

    cast as xs:boolean?','BIT'
    

    Which cast if the boolean is null, if it is, it will return null, or else it will return 1 or 0.

提交回复
热议问题