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. OPENXML - SQL

OPENXML - SQL

Scheduled Pinned Locked Moved Database
databasehelpquestionsharepointsales
2 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.
  • H Offline
    H Offline
    Hum Dum
    wrote on last edited by
    #1

    My Sp reading XML file data with help of OPENXML in SQL. There is slight problem in this.

    <Name_Address>
    <name>JCB SALES PVT</name>
    <address>24, SALAROURIA ARENA ADUGODI</address>
    <address>HOSUR MAIN ROAD, Honolulu</address>
    <country>N</country>
    </Name_Address>

    and my SQL query is

    SELECT @address = CONVERT(VARCHAR(150),[TEXT]) FROM OPENXML(@idoc,'/Name_Address/address', 0) where [text] is not null

    in @address i am getting last address tag value i.e

    HOSUR MAIN ROAD, Honolulu

    But it should be

    24, SALAROURIA ARENA ADUGODI, HOSUR MAIN ROAD, Honolulu

    How can i achieve this ? Help me, guide me to do this. regards

    H 1 Reply Last reply
    0
    • H Hum Dum

      My Sp reading XML file data with help of OPENXML in SQL. There is slight problem in this.

      <Name_Address>
      <name>JCB SALES PVT</name>
      <address>24, SALAROURIA ARENA ADUGODI</address>
      <address>HOSUR MAIN ROAD, Honolulu</address>
      <country>N</country>
      </Name_Address>

      and my SQL query is

      SELECT @address = CONVERT(VARCHAR(150),[TEXT]) FROM OPENXML(@idoc,'/Name_Address/address', 0) where [text] is not null

      in @address i am getting last address tag value i.e

      HOSUR MAIN ROAD, Honolulu

      But it should be

      24, SALAROURIA ARENA ADUGODI, HOSUR MAIN ROAD, Honolulu

      How can i achieve this ? Help me, guide me to do this. regards

      H Offline
      H Offline
      Hiren solanki
      wrote on last edited by
      #2

      Hum Dum wrote:

      SELECT @address = CONVERT(VARCHAR(150),[TEXT]) FROM OPENXML(@idoc,'/Name_Address/address', 0) where [text] is not null

      AFAIK the result is having two rows returning and At a time of converting SQL might picking up the second row and converting it accordingly, As It returns two rows having one column. But I can Provide you another solution for that. To first Retrieve the result and using COALESCE you can JOIN them together to produce expected result. Here's my work for you only.

      SELECT @address = COALESCE(@address+',' ,'') + [address]
      FROM
      (
      SELECT * FROM
      OPENXML (@idoc, 'Name_Address/address',3)
      WITH ([address] varchar(1000) '.')
      ) P
      SELECT @address

      It's working all right.

      Regards, Hiren. Microsoft Dynamics CRM My Recent Article: - Way to know which control have raised PostBack[^]

      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