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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:28:18+00:00 2026-05-24T03:28:18+00:00

I have an xml column in my SQL Server database that has records in

  • 0

I have an xml column in my SQL Server database that has records in the following format

<items>
<item>
      <data alias="Number">123N</data> 
      <data alias="Description">4 sq.mm Feed Through Terminal block in Grey colour</data>   
      <data alias="Standard Packing Quantity">100</data> 
 </item>
 <item>
      <data alias="Number">234N</data> 
      <data alias="Description">Toy</data> 
      <data alias="Standard Packing Quantity">100</data> 
 </item>
 <item>
      <data alias="Number">579N</data> 
      <data alias="Description">Doll</data> 
      <data alias="Standard Packing Quantity">100</data> 
 </item>
 <item>
      <data alias="Catalouge Number">234</data> 
      <data alias="Description">Vehicle</data> 
      <data alias="Standard Packing Quantity">324234</data> 
 </item>
 </items>

So to extract the data here I use:


SELECT 
       CatalogueNo,Description,StdPackingQty 
       from
       (select
 CAST(xml as xml).query('//data alias=''Description'']').value('.','nvarchar(225)')   [Description],   
 CAST(xml as xml).query('//data [@alias=''Catalouge Number'']')
.value('.','nvarchar(225)')[CatalogueNo],  
 CAST(xml as xml).query('//data [@alias=''Standard Packing Quantity'']').value('.','nvarchar(225)')[StdPackingQty]
        from [dbo].[cmsContentXml] )as hierarchy
Where CatalogueNo is not null

The problem I face is that the data that is extracted is all concatenated.
I need data in separate rows for each item,so the data needs to be in 3
columns and 4 rows.

Kindly help me resolve the issue asap and help write a query that would fetch data
free of concat

  • 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-05-24T03:28:19+00:00Added an answer on May 24, 2026 at 3:28 am

    You can use Cross Apply to breakdown the XML into separate data rows, and pull the data from those:

    SELECT 
        CatalogueNo,Description,StdPackingQty 
    from (
        select 
            i.value('data[@alias="Description"][1]','nvarchar(225)') [Description],
            i.value('data[@alias="Catalouge Number"][1]','nvarchar(225)') [CatalogueNo],
            i.value('data[@alias="Standard Packing Quantity"][1]','nvarchar(225)') [StdPackingQty]
        from [Connectwell].[dbo].[cmsContentXml]
        cross apply xml.nodes('/items/item') x(i)
    ) as hierarchy 
    --Where CatalogueNo is not null  
    

    Note: I’ve remmed out the where clause at the end as it will reduce you to just one row, whereas the question state you want 4 rows as the result.

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

Sidebar

Related Questions

I have a SQL Server database that contains an xml column. I need to
I have a XML column in database that may look like that ones: <sql-connection-info
I am using playframework with a legacy SQL Server 2008 database that has data
I have some XML data stored in a varchar(max) column on SQL Server 2005.
I'm using MS SQL Server 2008. I have a column of type XML that
I have an untyped XML column in Sql Server Database which holds values such
I have a few windwos services. They get xml column from Sql server manipulate
I'm hand-coding Linq to SQL Entities and have a large XML column that I
I have saved a dataset in the sql database in an xml column using
I have mysql table that has a column that stores xml as a string.

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.