Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:16:26+00:00 2026-06-03T07:16:26+00:00

I have a scalar xml variable: DECLARED @XML xml = ‘<rows> <row> <column1 attrib=

  • 0

I have a scalar xml variable:

DECLARED @XML xml =
'<rows>
    <row>
        <column1 attrib="" />
        <column2 attrib="" />
    </row>
    <!-- ... -->
</rows>';

I would like to split the data so that each row’s xml is assigned to a new record in a table:

Id | ... | XML
1  |     | '<row><column1 attrib="" /><column2 attrib="" /></row>'
2  |     | etc.
3  |     | etc.

I haven’t quite grasped xquery so I’m having trouble writing an insert statement that does what I want.

INSERT into MyTable( [XML])
SELECT @XML.query('row')

Now I know something is happening but it appears rather than doing what I intended and inserting multiple new records it is inserting a single record with an empty string into the [XML] column.

What am I not getting?

Clarification

I am not trying to get the inner text, subelements or attributes from each row using value(...). I am trying to capture the entire <row> element and save it to a column of type xml

I’ve experimented with nodes(...) and come up with:

INSERT into MyTable([XML])
SELECT C.query('*')
FROM @XML.nodes('rows/row') T(C)

Which is closer to what I want but the results don’t include the outer <row> tag, just the <column*> elements it contains.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:16:27+00:00Added an answer on June 3, 2026 at 7:16 am

    T-SQL Script:

    SET ANSI_WARNINGS ON;
    
    DECLARE @x XML =
    '<rows>
        <row Atr1="11" />
        <row Atr1="22" Atr2="B" />
        <row Atr1="33" Atr2="C" />
    </rows>';
    
    DECLARE @Table TABLE(Id INT NOT NULL, [XMLColumn] XML NOT NULL);
    
    INSERT  @Table (Id, XMLColumn)
    SELECT  ROW_NUMBER() OVER(ORDER BY @@SPID) AS Id,
            a.b.query('.') AS [XML]
    FROM    @x.nodes('//rows/row') AS a(b);
    
    SELECT  *
    FROM    @Table t;
    

    Results:

    Id XMLColumn
    -- --------------------------
    1  <row Atr1="11" />
    2  <row Atr1="22" Atr2="B" />
    3  <row Atr1="33" Atr2="C" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 'Malformed UTF-8 character' error when I'm putting some scalar data in XML::Simple
So I have val list:List[Any]; def toElement(a:Any):scala.xml.Elem; And I want to write somthing like
Suppose I have xml file with contents like this: <example name={name}/> Is it possible
I have a file data.xml in src/test/resources/ . How can I read that file
I would like to be able to parse XML that isn't necessarily well-formed. I'd
I am parsing XML file in scala using val data = XML.loadFile(changes.xml) I have
Say we have a class like this: import java.net.URL import xml._ class SearchData(xml: Node)
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
I have coded a view that relies on a scalar function value for one
I have 2 equal-length lists and I am trying to get scalar product of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.