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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:58:10+00:00 2026-05-25T23:58:10+00:00

Could someone show me some TSQL to use to query an xml file as

  • 0

Could someone show me some TSQL to use to query an xml file as if it were a table?

The file is on the server, “C:\xmlfile.xml”

And contains

<ArrayOfSpangemansFilter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SpangemansFilter>
        <FilterID>1219</FilterID>
        <Name>Fred</Name>
        <Code>510</Code>
        <Department>N</Department>
        <Number>305327</Number>
    </SpangemansFilter>
    <SpangemansFilter>
        <FilterID>3578</FilterID>
        <Name>Gary</Name>
        <Code>001</Code>
        <Department>B</Department>
        <Number>0692690</Number>
    </SpangemansFilter>
    <SpangemansFilter>
        <FilterID>3579</FilterID>
        <Name>George</Name>
        <Code>001</Code>
        <Department>X</Department>
        <Number>35933</Number>
    </SpangemansFilter>
</ArrayOfSpangemansFilter>

Example output I am after

FilterID    |Name       |Code       |Department             |Number
-------------------------------------------------------------------
1219        |Fred       |510        |N                      |305327
3578        |Gary       |001        |B                      |0692690
3579        |George     |001        |X                      |35933
  • 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-25T23:58:11+00:00Added an answer on May 25, 2026 at 11:58 pm
    set @xmlData='<?xml version="1.0"?>
    <ArrayOfSpangemansFilter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SpangemansFilter>
    <FilterID>1219</FilterID>
    <Name>Fred</Name>
    <Code>510</Code>
    <Department>N</Department>
    <Number>305327</Number>
    </SpangemansFilter>
    <SpangemansFilter>
    <FilterID>3578</FilterID>
    <Name>Gary</Name>
    <Code>001</Code>
    <Department>B</Department>
    <Number>0692690</Number>
    </SpangemansFilter>
    <SpangemansFilter>
    <FilterID>3579</FilterID>
    <Name>George</Name>
    <Code>001</Code>
    <Department>X</Department>
    <Number>35933</Number>
    </SpangemansFilter>
    </ArrayOfSpangemansFilter>'
    
    
    SELECT 
      ref.value('FilterID[1]', 'int') AS FilterID ,
      ref.value('Name[1]', 'NVARCHAR (10)') AS Name ,
      ref.value('Code[1]', 'NVARCHAR (10)') AS Code ,
      ref.value('Department[1]', 'NVARCHAR (3)') AS Department,
      ref.value('Number[1]', 'int') AS Number      
    FROM @xmlData.nodes('/ArrayOfSpangemansFilter/SpangemansFilter') 
    xmlData( ref )
    

    Produces:

    FilterID    Name       Code       Department Number
    ----------- ---------- ---------- ---------- -----------
    1219        Fred       510        N          305327
    3578        Gary       001        B          692690
    3579        George     001        X          35933
    

    Note: The [1] is needed to indicate that you want to select the first value of the sequence since the query may return more than one matched value per row (imagine your XML containing several FilterIDs per SpangemansFilter).

    I thought this was useful to know, so I Googled and read many posts until I found this one.

    UPDATE
    To load from file:

    DECLARE @xmlData XML
    SET @xmlData = (
      SELECT * FROM OPENROWSET (
        BULK 'C:\yourfile.xml', SINGLE_CLOB
      ) AS xmlData
    )
    

    SELECT @xmlData

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

Sidebar

Related Questions

Could someone please show me some code or a tutorial of how to use
Could someone show me a practical a use of the ... array method delcaration?
Given some code like below, could someone show me how I could align the
Could someone show some example about using dropbox api with django? Dropbox api is
Could someone please show me where to go for some decent tutorials for setting
I have been trying out some LINQ query can someone please show how to
Could someone show me in a snipet of code how to set the backlight
Given the example below, can someone please show me how this could be called?
Could someone please explain when would I want to use delegation instead of inheritance?
Could someone shed some light on this my NameValueCollection returns the Length property instead

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.