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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:56+00:00 2026-05-25T18:58:56+00:00

I was looking around and found no solution to this. I´d be glad if

  • 0

I was looking around and found no solution to this. I´d be glad if someone could help me out here:

I have a table, e.g. that has among others, following columns:

Vehicle_No, Stop1_depTime, Segment_TravelTime, Stop_arrTime, Stop_Sequence

The data might look something like this:

    Vehicle_No  Stop1_DepTime   Segment_TravelTime  Stop_Sequence  Stop_arrTime
    201         13000           60                  1
    201         13000           45                  2
    201         13000           120                 3
    201         13000                               4
    202         13300           240                 1
    202         13300           60                  2
    ...

and I need to calculate the arrival time at each stop from the departure time at the first stop and the travel times in between for each vehicle. What I need in this case would look like this:

Vehicle_No  Stop1_DepTime   Segment_TravelTime  Stop_Sequence   Stop_arrTime
        201         13000       60                  1           
        201         13000       45                  2           13060
        201         13000       120                 3           13105
        201         13000                           4           13225
        202         13300       240                 1
        202         13300       60                  2           13540           
        ...

I have tried to find a solution for some time but was not successful – Thanks for any help you can give me!


Here is the query that still does not work – I am sure I did something wrong with getting the table from the database into this but dont know where. Sorry if this is a really simple error, I have just begun working with MSSQL.

Also, I have implemented the solution provided below and it works. At this point I mainly want to understand what went wrong here to learn about it. If it takes too much time, please do not bother with my question for too long. Otherwise – thanks a lot 🙂

;WITH recCTE
AS
(
    SELECT  ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id,  ZAEHL_2011.dbo.L32.PlanAbfahrtStart,  ZAEHL_2011.dbo.L32.Fahrzeit, ZAEHL_2011.dbo.L32.Sequenz,  ZAEHL_2011.dbo.L32.PlanAbfahrtStart AS Stop_arrTime
    FROM     ZAEHL_2011.dbo.L32
    WHERE    ZAEHL_2011.dbo.L32.Sequenz = 1

    UNION ALL

    SELECT t. ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id, t. ZAEHL_2011.dbo.L32.PlanAbfahrtStart, t. ZAEHL_2011.dbo.L32.Fahrzeit,t. ZAEHL_2011.dbo.L32.Sequenz, r.Stop_arrTime + r. ZAEHL_2011.dbo.L32.Fahrzeit  AS Stop_arrTime
    FROM    recCTE AS r
    JOIN     ZAEHL_2011.dbo.L32 AS t
    ON      t. ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id = r. ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id
    AND     t. ZAEHL_2011.dbo.L32.Sequenz = r. ZAEHL_2011.dbo.L32.Sequenz + 1
)
SELECT  ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id,  ZAEHL_2011.dbo.L32.PlanAbfahrtStart,  ZAEHL_2011.dbo.L32.Fahrzeit, ZAEHL_2011.dbo.L32.Sequenz,  ZAEHL_2011.dbo.L32.PlanAbfahrtStart,
CASE WHEN Stop_arrTime =  ZAEHL_2011.dbo.L32.PlanAbfahrtStart THEN NULL ELSE Stop_arrTime END AS Stop_arrTime
FROM recCTE
ORDER BY  ZAEHL_2011.dbo.L32.Zaehl_Fahrt_Id,  ZAEHL_2011.dbo.L32.Sequenz
  • 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-25T18:58:57+00:00Added an answer on May 25, 2026 at 6:58 pm

    I’m quite sure this works:

    SELECT a.Vehicle_No, a.Stop1_DepTime, 
           a.Segment_TravelTime, a.Stop_Sequence, a.Stop1_DepTime +
      (SELECT SUM(b.Segment_TravelTime) FROM your_table b 
       WHERE b.Vehicle_No = a.Vehicle_No AND b.Stop_Sequence < a.Stop_Sequence)
    FROM your_table a
    ORDER BY a.Vehicle_No
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking around for a solution to this, I have found different methods. Some use
I've been looking around but I have not found a solution for this problem:
I've been looking around for a solution to this thing but I haven't found
I've been looking around for a solution to this, but haven't quite found one.
I have been looking around and even found a couple of related answers and
I have been looking around on the web and found some articles about the
I have been looking around ocn Google and Stackoverflow but haven't found what I
I've been looking around JQuery libraries for the URL hash, but found none that
I've been looking around, and haven't been able to find a solution to this
Looking around, I can't name a single web application (not web service) that uses

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.