2

I have the following example

DECLARE @MyXml XML 

SET @MyXml = CONVERT(XML, '<?xml version="1.0" ?>
                            <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                                <number xsi:nil="true" />
                            </root>')

SELECT @MyXml.value('(/root/number)[1]', 'INT') AS MyNumber

The above listing gives me a 0 instead of a NULL that I would expect. I know I am using Schema Instance, but shouldn't it be a widely accepted standard already?

fahadash
  • 3,133
  • 1
  • 30
  • 59

1 Answers1

1

You can use text():

LiveDemo

DECLARE @MyXml XML 

SET @MyXml = CONVERT(XML, 
  '<?xml version="1.0" ?>
   <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <number xsi:nil="true" />
  </root>')

SELECT @MyXml.value('(/root/number/text())[1]', 'INT') AS MyNumber
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275