Inserting XML

  • Comments posted to this topic are about the item Inserting XML

  • I don't know why you get an error. This code

    CREATE TABLE Mytest (id INT, x XML)

    INSERT mytest

    VALUES

    (1, CAST('1200' AS XML))

    , (2, CAST( '1201' AS XML))

    ... works just fine on my system.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Alan.B (5/31/2016)


    I don't know why you get an error. This code

    CREATE TABLE Mytest (id INT, x XML)

    INSERT mytest

    VALUES

    (1, CAST('1200' AS XML))

    , (2, CAST( '1201' AS XML))

    ... works just fine on my system.

    Agreed. No error in that code.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • There is no error in this code

  • darkunic (5/31/2016)


    There is no error in this code

    Agreed and that is why I read the question again. The question seemed more about 'how do I use this data to create an XML document?' rather than the code itself, so was there something else missing?

    Luckily got it right after reading the Stairway to XML articles.

    ...

  • me too found no error with this code.

  • Works fine for me too!

  • Alan.B (5/31/2016)


    I don't know why you get an error. This code

    CREATE TABLE Mytest (id INT, x XML)

    INSERT mytest

    VALUES

    (1, CAST('1200' AS XML))

    , (2, CAST( '1201' AS XML))

    ... works just fine on my system.

    works fine on at least the last three versions of sql server.

    Igor Micev,My blog: www.igormicev.com

  • I guessed the first option (about the = sign) as there was obviously something wrong with the question (the SQL will run fine) so I guessed that the typo was the omission of an '=' somewhere.

    Close, but no cigar 😉

  • Don't even know why I bothered answering this one - it was a pure guess, given that I didn't even understand half of the options, and the code doesn't cause an error!

    The explanation "The XML document needs to attribute for ID to be quoted" also doesn't make much sense, nor does it seem to relate to the question.

    Try again!

  • Another borked QotD.

  • Same here, no errors in the code.

  • should the code have been

    CREATE TABLE Mytest (id XML, x XML)

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • Don't know what the question should have been for that set of answers. Certainly not an error. +1

  • Choose the "correct" answer by eliminating the ones that were definitely correct.

    Agree with the rest, code is working and no error occurs. A bit strange though, because according to me the values are not well formed XML.

    From BOL

    Well-formed XML and the xml Data Type

    The xml data type implements the ISO standard xml data type. Therefore, it can store well-formed XML version 1.0 documents and also so-called XML content fragments with text nodes and an arbitrary number of top-level elements in an untyped XML column. The system checks that the data is well-formed, does not require the column to be bound to XML schemas, and rejects data that is not well-formed in the extended sense. This is true also of untyped XML variables and parameters.

Viewing 15 posts - 1 through 15 (of 36 total)

You must be logged in to reply to this topic. Login to reply