Updating Current table w next day's data while keeping only previous date data

  • I have a table that I get on the 1st of each month, and it has all the jobs scheduled for the entire month:

     

    SELECT [plannedstart]

    ,[plannedend]

    ,[machine]

    ,[Job]

    ,[Qty]

    FROM ScheduleJobs

     

    Day 1: The table has all the jobs scheduled for the entire month (Original Table)

    Days 2: I get another table that has the entire month of the job scheduled minus day 1 data

    Day 3: I get another table that has the entire month of the job scheduled minus the day 1 and day two data

    Day 4: I get another table that has the entire month of the job scheduled minus the day 1, day 2, and day 3

    And the same pattern goes for the rest of the month, day 5,  day 6, until the last day of the month.

    I want to write a query that allows me to update the Original table daily to keep only the previous day's data and replace the rest of its data with the subsequent current day's data.

     

    Any suggestion on how to accomplish this will be greatly appreciated.

    Thanks.

  • keep only the previous day's data and replace the rest of its data with the subsequent current day's data.

    DELETE

    FROM MyTable

    WHERE [DateColumn]<GETDATE()-1

    INSERT INTO MyTable

    SELECT ...

    FROM OtherTable

    WHERE [DateColumn] = GETDATE()

    ?

  • Thank you, pietlinden. I appreciate it.

  • I'm especially stayed aware of the article and I will get many benefits from it. Subsequently, thank you for sharing it.

  • I'm especially stayed aware of the article and I will get many benefits from it. Subsequently, thank you for sharing it.

     

    GarageBand App

    • This reply was modified 1 year, 10 months ago by  Matthew145.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply