SQL Server - Reading information from an XML document using OPENXML



Querying an XML document in SQL Server 2000 (and above) using OPENXML

DECLARE @x VARCHAR(8000)
SET @x = 
  '
    
        Michael
        Howard
    
    
        David
        LeBlanc
    
   '
   
DECLARE @h INT
EXECUTE sp_xml_preparedocument @h OUTPUT, @x 

SELECT * 
FROM OPENXML(@h, '/authors/author', 2)
WITH(
	firstname VARCHAR(20),
	lastname VARCHAR(20)
)

EXECUTE sp_xml_removedocument @h 

/*
firstname            lastname
-------------------- --------------------
Michael              Howard
David                LeBlanc
*/

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.