Greg's Blog

helping me remember what I figure out

SQL to XML

| Comments

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 [/code] The above will create an XML structure that has a root value of geoAreas and child elements of geoArea for each row found.