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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:24:49+00:00 2026-05-24T12:24:49+00:00

I have an application which logs changes to records in the production table to

  • 0

I have an application which logs changes to records in the “production” table to a “history” table. The history table is basically a field for field copy of the production table, with a few extra columns like last modified date, last modified by user, etc.

This works well because we get a snapshot of the record anytime the record changes. However, it makes it hard to determine unique status changes to a record. An example is below.

BoxID   StatusID   SubStatusID   ModifiedTime
 1         4            27       2011-08-11 15:31
 1         4            11       2011-08-11 15:28
 1         4            11       2011-08-10 09:07
 1         5            14       2011-08-09 08:53
 1         5            14       2011-08-09 08:19
 1         4            11       2011-08-08 14:15
 1         4            9        2011-07-27 15:52
 1         4            9        2011-07-27 15:49
 1         2            8        2011-07-26 12:00

As you can see in the above table (data comes from the real system with other fields removed for brevity and security) BoxID 1 has had 9 changes to the production record. Some of those updates resulted in statuses being changed and some did not, which means other fields (those not shown) have changed.

I need to be able, in TSQL, to extract from this data the unique status changes. The output I am looking for, given the above input table, is below.

BoxID   StatusID   SubStatusID   ModifiedTime
 1         4            27       2011-08-11 15:31
 1         4            11       2011-08-10 09:07
 1         5            14       2011-08-09 08:19
 1         4            11       2011-08-08 14:15
 1         4            9        2011-07-27 15:49
 1         2            8        2011-07-26 12:00

This is not as easy as grouping by StatusID and SubStatusID and taking the min(ModifiedTime) then joining back into the history table since statuses can go backwards as well (see StatusID 4, SubStatusID 11 gets set twice).

Any help would be greatly appreciated!

  • 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-24T12:24:49+00:00Added an answer on May 24, 2026 at 12:24 pm

    Does this do work for you

    ;WITH Boxes_CTE AS
        (
        SELECT Boxid, StatusID, SubStatusID, ModifiedTime,
            ROW_NUMBER() OVER (PARTITION BY Boxid ORDER BY ModifiedTime) AS SEQUENCE
        FROM Boxes
        )
    
    SELECT b1.Boxid, b1.StatusID, b1.SubStatusID, b1.ModifiedTime
    FROM Boxes_CTE b1
    LEFT OUTER JOIN Boxes_CTE b2 ON b1.Boxid = b2.Boxid
                AND b1.Sequence = b2.Sequence + 1
    WHERE b1.StatusID <> b2.StatusID
        OR b1.SubStatusID <> b2.SubStatusID
        OR b2.StatusID IS NULL
    ORDER BY b1.ModifiedTime DESC
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c++ application which logs to some file using log4cxx (RollingFile appender).
Hai I have developed a standalone application in which when an user logs in,
Hi I have an Standalone application in which when an user logs in a
I have an application which continuously receives data on a socket, and then logs
First some background. We have a vendor application which generates logs and configuration files
I have an application which is written in C and logs my function calls
I have an application which logs into an online site using POST form being
I have a quite ordinary web application which logs with slf4j, which is fine,
I have written an application which collects windows logs from linux, via the Zenoss
I have application which needs to use a dll (also written by me) which

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.