SQL to XML
Just came across this neat trick that uses SQL to generate XML on the fly:
CODE:
-
DECLARE @x xml
-
SET @x=(select geoAreaCode
-
, geoLevelCode
-
, geoLevelId
-
, geoAreaId
-
from tbl_geoLevel
-
where uuid =
-
for xml raw('geoArea'), root('geoAreas'), type)
-
SELECT @x AS geoAreaInfo
The above will create an XML structure that has a root value of geoAreas and child elements of geoArea for each row found.
About this entry
You’re currently reading “SQL to XML,” an entry on gregs
- Published:
- Wednesday, August 29th, 2007 at 4:12 pm
- Author:
- gregs
- Category:
- MS SQL
No comments
Jump to comment form | comments rss | trackback uri