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 xml: get xml values into CSV?

SQL xml: get xml values into CSV?

Scheduled Pinned Locked Moved Database
databasexmlquestion
4 Posts 2 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.
  • P Offline
    P Offline
    pankazmittal
    wrote on last edited by
    #1

    Hi In SQL 2005, I am trying to get a csv strin like "1212,1122,1123,1124" out of following xml. 1212 1122 1123 1124 Please advise how it can be done? Thanks Pankaj

    W 1 Reply Last reply
    0
    • P pankazmittal

      Hi In SQL 2005, I am trying to get a csv strin like "1212,1122,1123,1124" out of following xml. 1212 1122 1123 1124 Please advise how it can be done? Thanks Pankaj

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      The data you posted isn't in xml format so it's quite hard to say what the correct way would be. But let's suppose you have something like in the following example, then your query could be

      declare @testdata xml
      set @testdata =
      '<Root>
      <element>1212</element>
      <element>1122</element>
      <element>1123</element>
      <element>1124</element>
      </Root>'
      SELECT @testdata.query('for $e in /Root/element return concat(string($e),'', '')')

      The need to optimize rises from a bad design.My articles[^]

      P 1 Reply Last reply
      0
      • W Wendelius

        The data you posted isn't in xml format so it's quite hard to say what the correct way would be. But let's suppose you have something like in the following example, then your query could be

        declare @testdata xml
        set @testdata =
        '<Root>
        <element>1212</element>
        <element>1122</element>
        <element>1123</element>
        <element>1124</element>
        </Root>'
        SELECT @testdata.query('for $e in /Root/element return concat(string($e),'', '')')

        The need to optimize rises from a bad design.My articles[^]

        P Offline
        P Offline
        pankazmittal
        wrote on last edited by
        #3

        Thanks. With little tweak I can get desired result.

        W 1 Reply Last reply
        0
        • P pankazmittal

          Thanks. With little tweak I can get desired result.

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome :)

          The need to optimize rises from a bad design.My articles[^]

          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