I'm trying to use the openXML function with SQL Server 2012 for the first time and I'm running into an issue. If I have a node that has no value i.e
<amenity id="bathtub" name="Bathtub" />
I'm always getting a NULL value returned when using the code below to extract the data from the XML. Any normal element ie
<name>Attic Loft in a historical building</name>
seems to work fine. Is there an easy way of checking for the existence of a node using openXML?
DECLARE @XML AS XML, @hDoc AS INT, @SQL NVARCHAR (MAX)
SELECT @XML = XMLData FROM myXML
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML
SELECT *
FROM OPENXML(@hDoc, 'properties/property/amenities')
WITH
(
name [nvarchar](250) '../name',
externalId [nvarchar](50) '../id',
externalURL [nvarchar](250) '../landing_page_url',
description [nvarchar](max) '../description',
bathtub [bit] 'bathtub '
)
EXEC sp_xml_removedocument @hDoc
GO