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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:06:15+00:00 2026-06-11T14:06:15+00:00

I have a table I need to copy my data from (Log), into another

  • 0

I have a table I need to copy my data from (Log), into another table (BigTable). The Log table got the following data:

   LogID   LogTime             JobNumber    LogType   Description
   =====   =======             =========    =======   ===========
   1       2012-09-01 00:00:01   1          100       Accepted by D#12
   2       2012-09-01 00:05:33   1          100       Accepted by D#14
   3       2012-09-01 01:00:14   2          107       Message sent
   4       2012-09-01 05:00:53   2          100       Accepted by D#78
   5       2012-09-01 05:01:55   1          110       POB at Stop 1
   6       2012-09-01 05:02:22   3          100       Accepted by D#98
   7       2012-09-01 05:03:00   1          110       POB at Stop 2
   8       2012-09-01 05:04:00   2          110       POB at Stop 1
   9       2012-09-01 05:05:25   3          110       POB at Stop 1
  10       2012-09-01 05:15:36   1          200       Completed
  11       2012-09-01 05:20:45   2          200       Completed

The following data is already in BigTable

   JobNumber     Accepted_At     POB_At       Completed
   =========     ===========     ======       =========
    1            NULL            NULL         NULL
    2            NULL            NULL         NULL
    3            NULL            NULL         NULL

I am trying to update BigTable with values from Log. Note that in case of duplicate entries like LogID 1 and 2 (above), I am picking up only the latest date (2012-09-01 00:05:33). The same is desired for POB, as we are only interested in “POB at Stop 1”.

There are millions of rows in Log for lots of Job numbers, however, I need to get time for only those Jobs which are in BigTable only.
The Ideal table (after all updates) will look like the following:

   JobNumber   Accepted_At            POB_At                  Completed
   =========   ===========            ======                  =========
    1          2012-09-01 00:05:33    2012-09-01 05:01:55     2012-09-01 05:15:36
    2          2012-09-01 05:00:53    2012-09-01 05:04:00     2012-09-01 05:20:45
    3          2012-09-01 05:02:22    2012-09-01 05:05:25     NULL

Please note I am novice in this field. Any help is appreciated.
Thanks in advance.
Regards

  • 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-06-11T14:06:16+00:00Added an answer on June 11, 2026 at 2:06 pm

    You could aggregate the MAX dates in a CTE and then join it to BigTable for the update:

    ; WITH CTE AS (
        SELECT
        g.JobNumber
        , Accepted_At = MAX(CASE WHEN LogType = 100 THEN LogTime END)
        , POB_At = MAX(CASE WHEN LogType = 110 AND [Description] LIKE '%Stop%1' THEN LogTime END)
        , Completed = MAX(CASE WHEN LogType = 200 THEN LogTime END)
        FROM [Log] g
        GROUP BY g.JobNumber, g.LogType
    )
    UPDATE b
    SET Accepted_At = CTE.Accepted_At
    , POB_At = CTE.POB_At
    , Completed = CTE.Completed
    FROM CTE
    JOIN BigTable b ON b.JobNumber = CTE.JobNumber
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to copy a table from one server to another.for that I have
I need to copy data from one table to another. The tables do not
I need to copy some data from one table to another in Oracle, while
I have a table on another SQL server which I need to copy from
I need to copy some data from one table to another but I need
I need to copy a set of data from one table to another that
I have two table and I need to copy the data across from SRCServiceUsers
I need to extract records from a table, copy the data to a second
I need to copy data from original table and add custom column specified in
I need to copy data from one database to another with EF. E.g. I

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.