parse xml in sql

DECLARE @table TABLE ( yourXML XML )

DECLARE @xml XML

SET @xml = 
	(
	SELECT TOP 10 *
	FROM sys.objects
	FOR XML RAW, TYPE
	)

-- Spin up some dummy XML
INSERT INTO @table 
SELECT @xml

SELECT 
	t.*, 
	r.c.query('.'),
	r.c.value('@name', 'SYSNAME') AS tableName,
	r.c.value('@object_id', 'INT') AS objectId
FROM @table t
	CROSS APPLY t.yourXML.nodes('row') r(c)

posted on 2012-08-23 17:48  arui.wong  阅读(99)  评论(0编辑  收藏  举报

导航