Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Server and XML [modified]

SQL Server and XML [modified]

Scheduled Pinned Locked Moved Database
databasesql-serversysadminxmlquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jamie Nordmeyer
    wrote on last edited by
    #1

    Maybe it's just me, but I can't stand how Microsoft implemented XML in SQL Server, syntax wise, I mean, when it comes to selecting table data to XML. I always thought something like this made much more sense:

    Select
    Convert(xml, '<?xml version="1.0" encoding="utf-8" ?>
    <Employees>
    #foreach emp in emp begin#
    <Employee id="emp.EmployeeID#">
    <Manager id="#emp.BossID#">#emp.BossName#</Manager>
    <Addresses>
    #foreach addr in emp.Address1 begin#
    <Address id="#addr.AddressID#">#addr.Address1 + " " + addr.City + ", " + addr.State + " " addr.ZipCode#</Address>
    #end#
    </Addresses>
    </Employee>
    #end#
    </Employees>
    ') As EmployeeDoc
    From
    (
    Select
    emp.ID As EmployeeID
    ,emp.Name As EmployeeName
    ,boss.ID As BossID
    ,boss.Name As BossName
    ,addr.ID As AddressID
    ,addr.Address1
    ,addr.City
    ,addr.State
    ,addr.ZipCode
    From
    Employees emp
    Left Join Employees boss
    On emp.ManagerID = emp.ID
    Inner Join EmployeeAddresses empaddr
    On emp.ID = empaddr.EmployeeID
    Inner Join Addresses addr
    On empaddr.AddressID = addr.ID
    Where
    emp.TerminationDate Is Null
    ) tbl;

    I'm still working on learning the current syntax, so maybe this is a bit of a soapbox, but I feel better now anyways. :)

    Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan Portland, Oregon, USA

    modified on Monday, October 20, 2008 3:32 PM

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups