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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:15:51+00:00 2026-06-01T08:15:51+00:00

I have some data in an SQL table with an XML datatype column where

  • 0

I have some data in an SQL table with an XML datatype column where I need to return a list of elements that fall within a date range. The data looks like this:

folder Table – TBLfolder:
id – GUID
ClientId = GUID
CreatedDate: DateTime
contents: xml

the contents xml has a structure like:

<Contents>
  <Files>
   <File id="SOMEGUID">
   <StartDate>2001-11-07</StartDate>
   <EndDate>2062-11-14</EndDate>
   <Type code="jpeg">JPEG</Type>
   <Valid>true</Valid>
   </File>
   <File id="SOMEGUID">
   <StartDate>2012-09-01</StartDate>
   <EndDate>2065-11-14</EndDate>
   <Type code="jpeg">JPEG</Type>
   <Valid>true</Valid>
   </File>
   Files etc......
</Files>
</Contents>

I’m writing this in a stored proc where I pass in a client GUID and a start and end Date
I’m after a an xml column containing all files that fall between the date range from the latest folder record:

Here is what I have so far:

Select top 1 folder.contents.query('Contents/File/File
from TBLFolder
where clientID = @clientId
order by CreatedDate desc
For XML PATH ('Files')

What is the best way of filtering the Files node in the xml to only show files that fall between the start and end parameters?
I’m new to XML in SQL so unsure of the best way of tackling this.

I’ve tried a FLOWER statement and predicates on my query but having trouble with the datetime and conversions i’ve also been getting p1: p2: prefixes appearing on my elements.

the output I’m after is:

<Files>
       <File id="SOMEGUID">
       <StartDate>2001-11-07</StartDate>
       <EndDate>2062-11-14</EndDate>
       <Type code="jpeg">JPEG</Type>
       <Valid>true</Valid>
       </File>
       <File id="SOMEGUID">
       <StartDate>2012-09-01</StartDate>
       <EndDate>2065-11-14</EndDate>
       <Type code="jpeg">JPEG</Type>
       <Valid>true</Valid>
       </File>
       Files etc......
    </Files>
  • 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-01T08:15:53+00:00Added an answer on June 1, 2026 at 8:15 am
    DECLARE @x XML 
    SET @x='<Files>
           <File id="SOMEGUID">
           <StartDate>2001-11-07</StartDate>
           <EndDate>2062-11-14</EndDate>
           <Type code="jpeg">JPEG</Type>
           <Valid>true</Valid>
           </File>
           <File id="SOMEGUID">
           <StartDate>2001-11-08</StartDate>
           <EndDate>2065-11-14</EndDate>
           <Type code="jpeg">JPEG</Type>
           <Valid>true</Valid>
           </File>
            <File id="SOMEGUID">
           <StartDate>2001-11-19</StartDate>
           <EndDate>2065-11-14</EndDate>
           <Type code="jpeg">JPEG</Type>
           <Valid>true</Valid>
           </File>
        </Files>'
    
        edited...
    
        SELECT @x.query('
    for $i in /Files/File
    where $i/StartDate < ''2001-11-19''
    return $i
    ') as Resu 
    

    will produce :

    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 some XML data stored in a varchar(max) column on SQL Server 2005.
Basically I need to return some data from a SQL Server table in the
I have some xml data stored in an XML Column in a table in
If have a piece of code that gets some data from a sql database
I have a form that is trying to insert some data into an SQL
I have a Microsoft SQL server DB that imports some data which needs a
I've got an SQL table that I use to keep product data. Some products
I have a SQL Server DB table that has a column ReceivedDate defined as
I have a table in SQlite that I'm using to cache some data. I'm
In my SQL 2008 database table, I have one column name AUTHOR that contains

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.