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. Get XML node as 'text' data type

Get XML node as 'text' data type

Scheduled Pinned Locked Moved Database
databasehelpsysadminxmlperformance
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.
  • J Offline
    J Offline
    Jim Conigliaro
    wrote on last edited by
    #1

    We are using XML to pump data into a SQ: Server 2005 database. We pass an XML document into a stored procedure, the stored procedures chunks out the data and inserts it into the appropriate tables. Fine. Works great, easy to maintain, excelent performance. Here's the problem. One of the columns we are pushing data into is of data type text and the .value fuction of the XML node does not support conversion of a node's data to the 'text' data type. For example: CREATE PROCEDURE as MyProcedure @myData xml BEGIN INSERT INTO MyTable (FirstName, LastName, Notes) SELECT MyNode.value('FirstName[1]','varchar(50)'), MyNode.value('LastName[1]','varchar(100)'), MyNode.value('Notes[1]',**'text'**) FROM @myData.Notes('Person') as R(MyNode) END The problem is with the notes field. The cast to the data type text fails with the following error: The data type 'text' used in the VALUE method is invalid. The workaround thus far has been to use varchar(8000), but it will result in truncation if the data is too long. Any ideas? Jim Conigliaro jconigliaro@ieee.org

    A 1 Reply Last reply
    0
    • J Jim Conigliaro

      We are using XML to pump data into a SQ: Server 2005 database. We pass an XML document into a stored procedure, the stored procedures chunks out the data and inserts it into the appropriate tables. Fine. Works great, easy to maintain, excelent performance. Here's the problem. One of the columns we are pushing data into is of data type text and the .value fuction of the XML node does not support conversion of a node's data to the 'text' data type. For example: CREATE PROCEDURE as MyProcedure @myData xml BEGIN INSERT INTO MyTable (FirstName, LastName, Notes) SELECT MyNode.value('FirstName[1]','varchar(50)'), MyNode.value('LastName[1]','varchar(100)'), MyNode.value('Notes[1]',**'text'**) FROM @myData.Notes('Person') as R(MyNode) END The problem is with the notes field. The cast to the data type text fails with the following error: The data type 'text' used in the VALUE method is invalid. The workaround thus far has been to use varchar(8000), but it will result in truncation if the data is too long. Any ideas? Jim Conigliaro jconigliaro@ieee.org

      A Offline
      A Offline
      Arjan Einbu
      wrote on last edited by
      #2

      Try varchar(MAX) instead of text.

      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