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 8255903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:41:15+00:00 2026-06-08T01:41:15+00:00

I am fighting with @x.nodes(‘…’) as I am new to XQuery. I do have

  • 0

I am fighting with @x.nodes('...') as I am new to XQuery. I do have the XML variable @x constructed the following way:

CREATE TABLE tab (a int, b int, c int);
GO

INSERT INTO tab (a, b, c) VALUES (1, 11, 111);
INSERT INTO tab (a, b, c) VALUES (2, 22, 222);
INSERT INTO tab (a, b, c) VALUES (3, 33, 333);
INSERT INTO tab (a, b, c) VALUES (4, 44, 444);
GO

DECLARE @x XML = (SELECT * FROM tab FOR XML RAW, TYPE);

When its content is displayed, it looks like:

<row a="1" b="11" c="111" />
<row a="2" b="22" c="222" />
<row a="3" b="33" c="333" />
<row a="4" b="44" c="444" />

i.e. single multiline string. How can shred the single multielement XML value to many single-element value in the destination table? (I am aware of the official nodes() Method (xml Data Type) documentation page, but I am doing something wrong.)

CREATE TABLE tab2 (e XML);

??? ... @x.nodes('//row') ... ???

Thanks, Petr

P.S. The question is loosely related to Service Broker — how to extract the rows from the XML message?

  • 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-08T01:41:19+00:00Added an answer on June 8, 2026 at 1:41 am

    OK – so you have an XML variable that contains that XML you posted – and you need to shred this into its own individual bits?

    Try something like this:

    SELECT
        value_a = c.value('(@a)[1]', 'int'),
        value_b = c.value('(@b)[1]', 'int'),
        value_c = c.value('(@c)[1]', 'int') 
    FROM @x.nodes('/row') AS T(c)
    

    That gives me an output of :

    enter image description here

    Is that what you’re looking for?

    Update: ok, if I understand you correctly, this is what you want:

    SELECT
        c.query('.')
    FROM @x.nodes('/row') AS T(c)
    

    Output:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been fighting this all day. Inside my styles.xml file I have color information
I'm fighting with OSX's packageMaker as it doesn't allow me to create a '.pkg'.
I've been fighting my way through the process of migrating a (previously self-hosted) WCF
After fighting several versions of the CoreKeyGen created by some minamoto guy, a new
I'm still fighting with GCC - compiling the following inline assembly code (with -fasm-blocks
I have fighting to get a IN parameter to work inside of a LIKE
I've been fighting with this for an hour now. I'm parsing an XML-string with
I have been fighting with this for quite some time and have found a
I'm fighting about two days with the following problem and hope you can give
I have been fighting this for a while, can't figure out why do I

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.