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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:37:40+00:00 2026-05-31T13:37:40+00:00

Let me start by saying I know my subject is not exactly correct but

  • 0

Let me start by saying I know my subject is not exactly correct but I don’t know how to phrase it.

Rather than try to explain what I am trying to do, let me show you:

Below is a snippet of the pertinent data from my table (I am using CONVERT to trim date/time fields to the values we need. All dates are “XX/XX/XXXX 00:00:00.000” and all times are “01/01/1900 XX:XX:XX.000” where XX is a true value and 00 is placeholder).

CALLNBR     DATE       START      END
----------- ---------- ---------- ----------
0000182867  03/07/2012 10:55:00   12:20:00
0000182867  03/07/2012 12:20:00   13:00:00
0000182779  03/06/2012 14:29:00   15:03:00
0000182749  03/06/2012 15:15:00   15:30:00
0000182748  03/07/2012 10:40:00   12:30:00
0000182748  03/07/2012 12:30:00   13:20:00
0000182740  03/06/2012 11:00:00   11:30:00
0000182740  03/06/2012 11:30:00   12:00:00
0000182735  03/07/2012 09:10:00   10:00:00
0000182735  03/07/2012 10:00:00   10:40:00
0000182735  03/06/2012 14:40:00   15:10:00
0000182735  03/06/2012 15:10:00   15:30:00
0000182735  03/06/2012 15:30:00   16:45:00

I need to string times together where one records end time is the next one’s start time. I am trying to get a result similar to (Filtered by CALLNBR 182735):

CallNbr     DATE       t1Start    t1end      t2Start    t2end      t3Start    t3end
----------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0000182735  03/06/2012 14:40:00   15:10:00   15:10:00   15:30:00   15:30:00   16:45:00
0000182735  03/07/2012 09:10:00   10:00:00   10:00:00   10:40:00   NULL       NULL

But the result I AM getting is:

CallNbr     DATE       t1Start    t1end      t2Start    t2end      t3Start    t3end
----------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0000182735  03/06/2012 14:40:00   15:10:00   15:10:00   15:30:00   15:30:00   16:45:00
0000182735  03/06/2012 15:10:00   15:30:00   15:30:00   16:45:00   NULL       NULL
0000182735  03/07/2012 09:10:00   10:00:00   10:00:00   10:40:00   NULL       NULL

My issue is with the middle record, whose values are in the first record returned:

0000182735  03/06/2012 15:10:00   15:30:00   15:30:00   16:45:00   NULL       NULL

Unfortunately I can’t suppress NULLS by t3Start or t3End because that would eliminate the record for (in this instance) 03/07/2012.

0000182735  03/07/2012 09:10:00   10:00:00   10:00:00   10:40:00   NULL       NULL

And now for the SELECT (To make it more readable, I am stripping out my CONVERT’ers):

    SELECT
      t1.CallNbr,
      t1.STRTDATE,
      t1.strttime as t1Start,
      t1.endtme   as t1end,
      t2.strttime as t2Start,
      t2.endtme   as t2end,
      t3.strttime as t3Start,
      t3.endtme as t3end
    FROM       TableA t1
    INNER JOIN TableA t2 ON t1.endtme    = t2.strttime
                        AND t1.strtdate  = t2.strtdate
                        AND t1.CALLNBR   = t2.CALLNBR
                        AND t1.LINITMTYP = 'L' 
    LEFT  JOIN TableA t3 ON t3.CALLNBR  = t2.CALLNBR
                        AND t3.strttime = t2.endtme
                        AND t3.strtdate = t1.strtdate
    WHERE t1.CALLNBR = '0000182735'
    ORDER BY t1.CALLNBR, t1.strtdate

Even if you can’t help, thank you for taking the time to read through it.

Thanks,

Phillip

  • 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-31T13:37:41+00:00Added an answer on May 31, 2026 at 1:37 pm

    If you are able to use the ROW_NUMBER() functionality, then I would do the following. This makes sure that the query only pulls from the starting, and not the middle. You can possibly clean the query up a little this way, but I am not sure. All you should need is the RowNum = 1, but you can add extra security of not allowing any overlap using parent table rownum > child table rownum that I added in comments

    SELECT t1.CallNbr, t1.StrtDate, t1.StrtTime, t1.EndTime, t1.LINITMTYP,
        ROW_NUMBER() OVER (PARTITION BY t1.CALLNBR, t1.strtdate ORDER BY t1.StrtTime) AS RowNum
    INTO #MyTemp
    FROM TableA AS t1
    
    SELECT
          t1.CallNbr,
          t1.STRTDATE,
          t1.strttime as t1Start,
          t1.endtme as t1end,
          t2.strttime as t2Start,
          t2.endtme as t2end,
          t3.strttime as t3Start,
          t3.endtme as t3end
        FROM #MyTemp t1
            JOIN #MyTemp t2 ON t1.endtme    = t2.strttime
                      AND t1.strtdate  = t2.strtdate
                      AND t1.CALLNBR   = t2.CALLNBR
                      AND t1.LINITMTYP = 'L' 
                      --You could add extra security using the following
                      --AND t2.RowNum > t1.RowNum
        LEFT JOIN #MyTemp t3 ON t3.CALLNBR  = t2.CALLNBR
                           AND t3.strttime = t2.endtme
                           AND t3.strtdate = t1.strtdate
                           --You could add extra security using the following
                           --AND t3.RowNum > t2.RowNum
        WHERE t1.CALLNBR = '0000182735' 
            AND t1.RowNum = 1
        ORDER BY t1.CALLNBR, t1.strtdate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start off by saying I know this is probably not the correct
Let me start by saying I know about position() but I can't seem to
Let me start of by saying that as I don't know how to search
Let me start off by saying, I'm not new to programming but am very
Let me start by saying that this is working correctly, but I know it's
Let me start by saying that I do not advocate this approach, but I
Let me start by saying this is a homework assignment, I don't need any
Let me start by saying im not 100% the way Im handling this is
Let me start out by saying that I'm not a C developer and I
Let me start by saying that I know nothing about Cron, so sorry. How

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.