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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:04:53+00:00 2026-05-18T11:04:53+00:00

I have a table called People with a columns of datatype xml called properties

  • 0

I have a table called People with a columns of datatype xml called properties. I’ve used this to store random information about each person basically allowing people to store any extra data that are added in the future without a database redesign. Not all people will have the same elements in their xml.

CREATE TABLE [dbo].[Person](
 [PersonID] [bigint] IDENTITY(1,1) NOT NULL,
 [PersonType] [nvarchar](50) NULL,
 [Title] [nvarchar](5) NULL,
 [Forename] [nvarchar](60) NULL,
 [Surname] [nvarchar](60) NULL,
 [Company] [nvarchar](60) NULL,
 [Properties] [xml] NULL
)

An example of the xml is:

<PropertyList xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Property Name="Class">Class A</Property>
  <Property Name="CarRegistration">123456</Property>
  <Property Name="MedicalNotes">None</Property>
</PropertyList>

First question is I can’t seem to find a SQL query that will allow me to get a list of records that match criteria stored in the xml.

For example how would i get all records where the Class="Class A". I’ve tried :

SELECT 
    PersonID, 
    Properties.value('/PropertyList/Property[@Name="Class"][1]','nvarchar(50)') 
FROM Person

I know this is incorrect but I get the error “requires a singleton (or empty sequence)” and I’m not quite sure whats gone wrong.

And second side question is I’ve combined several older databases into a single person list however the old database frontends still need to access their bit of the data. My plan was to create a view for each database frontend with a layout specific for its needs all linking back to the main people table. However some of their fields are now stored in the XML. Is there any way of creating a view to update the XML without seeing the xml i.e. so it looks and acts just like a view on any other table. I hope i explained that correctly. For each view I will have a specific set of XML properties I need them to edit and all records will have them so its not so random.

Thanks for any help.

  • 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-18T11:04:54+00:00Added an answer on May 18, 2026 at 11:04 am

    Your XQuery should be:

    SELECT PersonID, 
           Properties.value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') 
    FROM dbo.Person
    

    Does that help??

    Update: to make it clearer for others – I’ve added parenthesis around the /PropertyList/Property[@Name="Class"] expression, so that this will evaluate to potentially a list of values, and then the [1] after the parenthesis will select the first (and most often only) value (as a singleton) of that list so it can be converted to a NVARCHAR(50) string.

    value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') 
           !                                     !
    

    is NOT the same as

    value('/PropertyList/Property[@Name="Class"][1]','NVARCHAR(50)') 
    

    Update 2: if you want to create a view – sure, no reason not to! 😉

    You could definitely create something like:

    CREATE VIEW dbo.YourViewName
    AS
        SELECT
            PersonID, PersonType, Title, 
            ForeName, Surname, Company,
            Properties.value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') AS 'Class',
            Properties.value('(/PropertyList/Property[@Name="CarRegistration"])[1]','NVARCHAR(50)') AS 'CarRegistration',
            Properties.value('(/PropertyList/Property[@Name="MedicalNotes"])[1]','NVARCHAR(50)') AS 'MedicalNotes'
    

    from your table and “break up” the XML into columns on your view. Is that what you’re looking for??

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

Sidebar

Related Questions

I have a table called People one of the columns is an xml field
Alright. So I have a table called contacts. In this table I have people
I have a table which called people, and I have there 2 columns, name
I have table called posts in my DB. Each post has field called social_network
I have a table called ProjectRegion. It has two columns, an id and a
I have a table called scheduler_sched which has several columns, including a column called
I have a table called tblRentalRates with the following columns: rate_id (int) rate_startdate (datetime)
I have a table in my database called OrderItemType which has about 5 records
I have two tables. My first table is called as WORLD and this table
I have a table called PEOPLE that shows Name Sex ++++ ++++++ Tom 1

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.