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. T-SQL and XML question.

T-SQL and XML question.

Scheduled Pinned Locked Moved Database
questionjavascriptdatabasecomxml
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

    A website I'm writing uses jQuery and a plugin called Flexigrid, that expects an XML document in this format:

    <rows>
    <page>1</page>
    <total>7</total>
    <row id="1">
    <cell>1</cell>
    <cell>SomeName</cell>
    <cell>SomeDescription</cell>
    </row>
    <row id="2">
    <cell>2</cell>
    <cell>SomeName</cell>
    <cell>SomeDescription</cell>
    </row>
    </rows>

    I managed to make it work with the following SQL:

    Select
    1 As 'page'
    ,7 As 'total'
    ,(
    Select
    ID As '@id'
    ,(Select ID As 'cell' From Table Where ID = dc.ID For Xml Path(''), Type)
    ,(Select [Name] As 'cell' From Table Where ID = dc.ID For Xml Path(''), Type)
    ,(Select [Description] As 'cell' From Table Where ID = dc.ID For Xml Path(''), Type, Elements XsiNil)
    From
    Table dc
    For Xml Path('row'), Type
    )
    For Xml Path('rows'), Type

    Is there a better way to do this? I've scoured Google, and wasn't able to find anything. This works, but it seems like there must be a better way that I'm just not finding. Thanks.

    Jamie Nordmeyer
    Portland, Oregon, USA
    http://www.feralcodemonkies.com

    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