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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:56:28+00:00 2026-05-12T17:56:28+00:00

I have the following problem: Suppose I have a table with the following fields:

  • 0

I have the following problem:

Suppose I have a table with the following fields:
[ID]
[Start Date]
[Status Date]
[Status Description]

[ID] is not unique, and so I may have:

ID  Start Date   Status Date      Status
123 01/01/2009  01/01/2009       Start
123 01/01/2009  01/02/2009       Change
123 01/01/2009  01/03/2009       Change
123 01/01/2009  01/07/2009       Stop

What I want to do is the following: run an insert into on all the records where [Status] = ‘Start’.

When that is done, the part that I don’t know how to do is then the following: I want to update [Status Date] and [Status] to that of the final status date. I.e. what I want is:

ID  Start Date   Status Date      Status
123 01/01/2009  01/07/2009       Stop

Any suggestions?

[EDIT]

I’m using SQL Server 2008

With insert into I mean create a new table and insert into it only those records that have status “Start”, thereby achieving a table with unique IDs

  • 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-12T17:56:29+00:00Added an answer on May 12, 2026 at 5:56 pm

    I’m not sure if I get your right. You want the latest date and status for any ID?

    That would be:

    SELECT    a.ID, a.StatusDate, a.Status
    FROM      Table AS a
    INNER JOIN 
    (
        SELECT   ID, Max(StatusDate) AS StatusDate
        FROM     Table
        GROUP BY ID
    ) AS b
    ON        a.ID = b.ID
    AND       a.StatusDate = b.StatusDate
    

    Now, what table do you want to update with this? What do you mean by “run an insert into on all the records where [Status] = ‘Start'”? Did you create a second table and insert this date into it?

    EDIT:

    Okay, so I guess you want to update the data in this newly created table then?

    Try this (I hope I have no syntax error in this, I don’t have an SQL server here right now to try it):

    UPDATE    c
    SET       c.StatusDate = a.StatusDate,
              c.Status = a.Status
    FROM      NewTable AS c
    INNER JOIN Table AS a
    ON        c.ID = a.ID
    INNER JOIN 
    (
        SELECT   ID, Max(StatusDate) AS StatusDate
        FROM     Table
        GROUP BY ID
    ) AS b
    ON        a.ID = b.ID
    AND       a.StatusDate = b.StatusDate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Propose to consider the following problem. Suppose we have some composite object. Are there
I have a table with the following fields: id VARCHAR(32) PRIMARY KEY, parent VARCHAR(32),
Suppose that we have the following partial ER diagram: Notice that the attachments table
suppose you are given the following problem. You have two index sets that have
Suppose I have a table that looks like the following id | location |
I have following problem where I have to group different transactions into timeslots. Suppose
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of

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.