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

  • Home
  • SEARCH
  • 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 9212829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:36:51+00:00 2026-06-18T01:36:51+00:00

I have a table! CREATE TABLE [dbo].[XmlTable]( [XmlId] [int] IDENTITY(1,1) NOT NULL, [XmlDocument] [xml]

  • 0

I have a table!

CREATE TABLE [dbo].[XmlTable](
    [XmlId] [int] IDENTITY(1,1) NOT NULL,
    [XmlDocument] [xml] NOT NULL,
 CONSTRAINT [PK_XmlTable] PRIMARY KEY CLUSTERED 
(
    [XmlId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


GO

With a schema structure: stored in the xml column

    <dev:Doc xmlns:dev="http://www.w3.org/2001/XMLSchema" SchemaVersion="0.1" Settings="Testing" Title="Ordering">
  <dev:Base RevisionNumber="0" Baseid="34433" />
  <dev:Rev Time="2013-01-21T15:08:00">
    <dev:Person Name="Me" Systemid="54654" />
  </dev:Rev>
  <dev:Functions Id="A1">
    <dev:A1 Number="1">
      <dev:Codes>D</dev:Codes>
      <dev:Required>true</dev:Required>
      <dev:Informational>false</dev:Informational>
      <dev:Visitors>
        <dev:Visitor Name="Dev01" Location="STLRF">
          <dev:Divisions>
            <dev:Division Number="1" Name="TFR3" Usage="Monitor">
              <dev:Description>Development Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="2" Name="DEF32" Usage="Monitor">
              <dev:Description>Testing Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="3" Name="DEP13" Usage="None">
              <dev:Description>Guided Fundamentals</dev:Description>
            </dev:Division>
          </dev:Divisions>
        </dev:Visitor>
        <dev:Visitor Name="Dev02" Location="STLRF">
          <dev:Divisions>
            <dev:Division Number="1" Name="TFR3" Usage="Monitor">
              <dev:Description>Development Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="2" Name="DEF32" Usage="Monitor">
              <dev:Description>Testing Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="3" Name="DEP13" Usage="None">
              <dev:Description>Guided Fundamentals</dev:Description>
            </dev:Division>
          </dev:Divisions>
        </dev:Visitor>
        <dev:Visitor Name="Dev03" Location="FGRTY">
          <dev:Divisions>
            <dev:Division Number="1" Name="TFR3" Usage="Monitor">
              <dev:Description>Development Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="2" Name="DEF32" Usage="Monitor">
              <dev:Description>Testing Fundamentals</dev:Description>
            </dev:Division>
            <dev:Division Number="3" Name="DEP13" Usage="None">
              <dev:Description>Guided Fundamentals</dev:Description>
            </dev:Division>
          </dev:Divisions>
        </dev:Visitor>
      </dev:Visitors>
      <dev:Senders>
        <dev:Sender Name="FGY(14A)" />
      </dev:Senders>
    </dev:A1>
  </dev:Functions>
  <dev:Functions Id="A2">
    <dev:A2 Number="1">
      <dev:Codes>C</dev:Codes>
      <dev:Required>true</dev:Required>
      <dev:Informational>false</dev:Informational>
      <dev:Remarks>Support</dev:Remarks>
      <dev:Notes>Ready</dev:Notes>
      <dev:Visitors>
        <dev:Visitor Name="GHFF">
          <dev:Divisions>
            <dev:Division Number="0" Name="Trial" Usage="None">
              <dev:FromLocation>LOPO</dev:FromLocation>
              <dev:ToLocation>RDSS</dev:ToLocation>
              <dev:Description>Rich Filter</dev:Description>
            </dev:Division>
          </dev:Divisions>
        </dev:Visitor>
      </dev:Visitors>
      <dev:Senders>
        <dev:Sender Name="W33R" />
      </dev:Senders>
      <dev:IsReady>true</dev:IsReady>
      <dev:IsCall>false</dev:IsCall>
    </dev:A2>
    <dev:A2 Number="2">
      <dev:Codes>A</dev:Codes>
      <dev:Required>true</dev:Required>
      <dev:Informational>false</dev:Informational>
      <dev:Remarks>Loader Ready</dev:Remarks>
      <dev:Notes>Ready</dev:Notes>
      <dev:Visitors>
        <dev:Visitor Name="UDT">
          <dev:Divisions>
            <dev:Division Number="0" Name="Trial" Usage="None">
              <dev:FromLocation>TYUJ</dev:FromLocation>
              <dev:ToLocation>DETF</dev:ToLocation>
              <dev:Description>Web Enhance</dev:Description>
            </dev:Division>
          </dev:Divisions>
        </dev:Visitor>
      </dev:Visitors>
      <dev:Senders>
        <dev:Sender Name="RJ4" />
      </dev:Senders>
      <dev:IsReady>true</dev:IsReady>
      <dev:IsCall>false</dev:IsCall>
    </dev:A2>
  </dev:Functions>
</dev:Doc>

I am trying to return the Revision Number, Functions id, number, Visitor, location of the visitors, Sender name,

Something like:

RevNumber Function Id  Number  Visitor Location Sender
========= =========== ======== ======= ======== ======
  0          A1          1      Dev01   STLRF   FGY(14A)
  0          A1          1      Dev02   STLRF   FGY(14A)
  0          A1          1      Dev03   FGRTY   FGY(14A)
  0          A2          1      GHFF    NULL    W33R
  0          A2          2      UDT     NULL    RJ4

Here is my insert into the table

INSERT INTO XmlTable(XMLDocument)
SELECT * FROM OPENROWSET(
   BULK 'C:\Users\123\Desktop\Practice.xml',
   SINGLE_BLOB) AS x;

I have used the query, and values method to pull back a partial list but now i am stuck. I appreciate any help. Thanks!

Here is the query

;WITH XMLNAMESPACES ( DEFAULT 'http://www.w3.org/2001/XMLSchema' )
SELECT  Visitor.query('.') AS XmlFragment,
        Visitor.value('@Name', 'NVARCHAR(MAX)') AS VisitorName,
        Visitor.value('@Location', 'NVARCHAR(MAX)') AS Location
FROM    XMLTable 
        CROSS APPLY XmlDocument.nodes('/Doc/Functions/A1/Visitors/Visitor') XD ( Visitor );
  • 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-18T01:36:52+00:00Added an answer on June 18, 2026 at 1:36 am

    You’re on the right track – you just need to add a second CROSS APPLY to get at the list of nodes inside the <Visitor> XML node:

    ;WITH XMLNAMESPACES ( DEFAULT 'http://www.w3.org/2001/XMLSchema' )
    SELECT  
        Divisions.value('@Number', 'INT'),
        Divisions.value('@Name', 'VARCHAR(50)'),
        Divisions.value('@Usage', 'VARCHAR(100)'),
        Visitor.value('@Name', 'NVARCHAR(MAX)') AS VisitorName,
        Visitor.value('@Location', 'NVARCHAR(MAX)') AS Location
    FROM
        @XmlTable
    CROSS APPLY 
        XmlDocument.nodes('/Doc/Functions/A1/Visitors/Visitor') AS XD(Visitor)
    CROSS APPLY 
        Visitor.nodes('Divisions/Division') AS XD2(Divisions)
    

    Returns an output like:

    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 have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
I have the following table: CREATE TABLE [dbo].[Tree]( [AutoID] [int] IDENTITY(1,1) NOT NULL, [Category]
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have a following table CREATE TABLE [dbo].[test_table] ( [ShoppingCartID] [int] IDENTITY(1,1) NOT NULL,
I have a table defined as: CREATE TABLE [dbo].[procInfo]( [id] [int] IDENTITY(1,1) NOT NULL,
I have the following table: CREATE TABLE [dbo].[PartsWork]( [parts_work_id] [int] IDENTITY(1,1) NOT NULL, [experiment_id]
I have the following table: CREATE TABLE [dbo].[omgbbq]( [tbl_key] [int] IDENTITY(1,1) NOT NULL, [name]
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have a table like this: CREATE TABLE [dbo].[Scores]( [Id] [int] IDENTITY(1,1) NOT NULL,
I have a table described as CREATE TABLE [dbo].[Project]( [id] [int] IDENTITY(1,1) NOT NULL,

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.