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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:44+00:00 2026-05-11T20:12:44+00:00

I’ve got a very large xml data set that is structured like the following:

  • 0

I’ve got a very large xml data set that is structured like the following:

<root>
    <person>
        <personid>HH3269732</personid>
        <firstname>John</firstname>
        <lastname>Smith</lastname>
        <entertime>01/02/2008 10:15</entertime>
        <leavetime>01/02/2008 11:45</leavetime>
        <entertime>03/01/2008 08:00</entertime>
        <leavetime>03/01/2008 10:00</leavetime>
        ... 
        // number of enter times and leave times vary from person to person
        // there may not be a final leave time (ie, they haven't left yet)
    </person>
    ...
</root>

The structure of the data is not under my control. This data is currently residing in a single xml column in a single row in MS SQL Server 2005. I am trying to construct a query which results in the following output:

HH3269732   John   Smith   01/02/2008 10:15   01/02/2008 11:45
HH3269732   John   Smith   03/01/2008 08:00   01/02/2008 10:00
HH3269735   Mark   Pines   02/01/2008 09:00   NULL
HH3263562   James  Frank   NULL               NULL
HH3264237   Harold White   04/18/2008 03:00   04/18/2008 05:00
...

My query currently looks like the following:

DECLARE @xml xml
SELECT @xml = XmlCol FROM Data

SELECT
    [PersonId] = Persons.PersonCollection.value('(personid)[1]', 'NVARCHAR(50)')
    ,[First Name] = Persons.PersonCollection.value('(firstname)[1]', 'NVARCHAR(50)')
    ,[Last Name] = Persons.PersonCollection.value('(lastname)[1]', 'NVARCHAR(50)')
    ??????
FROM @xml.nodes('root\person') Persons(PersonCollection)

That query may not be 100% right as I’m pulling it from memory, but the problem I’m having is that I don’t know how to include the entertime leavetime sequence elements in such a way as to get the desired rowset that I indicated above.

Thanks.

UPDATE:
I wanted to add that a given person record may have no entertime/leavetime sequence elements at all, but still needs to be returned in the rowset. I have updated the example of the desired output to reflect this.

  • 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-11T20:12:44+00:00Added an answer on May 11, 2026 at 8:12 pm
    with cte_entertime as (
    SELECT
        [PersonId] = t.c.value('(../personid)[1]', 'NVARCHAR(50)')
        ,[First Name] = t.c.value('(../firstname)[1]', 'NVARCHAR(50)')
        ,[Last Name] = t.c.value('(../lastname)[1]', 'NVARCHAR(50)')
        ,[Entertime] = t.c.value('.', 'NVARCHAR(50)')
        ,[entry_number] = ROW_NUMBER() OVER (ORDER BY t.c)
    FROM @x.nodes('root/person/entertime') t(c))
    , cte_leavetime as (
        SELECT
        [Leavetime] = t.c.value('.', 'NVARCHAR(50)')
        ,[entry_number] = ROW_NUMBER() OVER (ORDER BY t.c)
    FROM @x.nodes('root/person/leavetime') t(c))
    SELECT PersonID
        , [First Name]
        , [Last Name] 
        , [Entertime]
        , [Leavetime]
        FROM cte_entertime e 
        LEFT OUTER JOIN cte_leavetime l on e.entry_number = l.entry_number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 108k
  • Answers 108k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try casting it as strGroupName = (_TCHAR*)_tcschr(strTempName, 92); Seems to… May 11, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer This worked: SET UNICODE YES (at the top of the… May 11, 2026 at 9:17 pm
  • Editorial Team
    Editorial Team added an answer I would use and in your code behind, load up… May 11, 2026 at 9:17 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.