gregs

Archive for August, 2007

SQL to XML

by gregs on Aug.29, 2007, under MS SQL

Just came across this neat trick that uses SQL to generate XML on the fly:

CODE:
  1. DECLARE @x xml
  2. SET @x=(select geoAreaCode
  3. , geoLevelCode
  4. , geoLevelId
  5. , geoAreaId
  6. from tbl_geoLevel
  7. where uuid =
  8. for xml raw('geoArea'), root('geoAreas'), type)
  9. 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.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!