I have a simple table called tblFiles in SQL Server 2008 R2.
tblFiles as the following columns:
- FileId - (int) primary key
- FileName - (nvarchar 255)
- MetaData - (xml) has been configured with an XML schema for validation.
The schema is as follows:
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="FileMetaData">
<xs:complexType>
<xs:sequence>
<xs:element name="CreatedDate" type="xs:time"/>
<xs:element name="ModifiedDate" type="xs:time"/>
<xs:element name="AccessDate" type="xs:time"/>
</xs:sequence>
<xs:attribute name="Length" type="xs:integer"/>
</xs:complexType>
</xs:element>
</xs:schema>
A sample XML metadata entry in a record is:
<?xml version="1.0"?>
<FileMetaData Length="26">
<CreatedDate>10:13:53.1008</CreatedDate>
<ModifiedDate>10:14:02.0327</ModifiedDate>
<AccessDate>10:13:53.1008</AccessDate>
</FileMetaData>
I've populated the database with a load of files and its associated metadata.
What I'm trying to work out is how to write a query that will return return all records that have a length set in the XML that is between X and Y?
How do I navigate the XML in the SQL query?
TIA