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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:51:09+00:00 2026-05-14T14:51:09+00:00

I’m writing an application that models train routes, which are stored in the database

  • 0

I’m writing an application that models train routes, which are stored in the database table [TrainStop] as follows:

TrainServiceId
StationCode
StopIndex
IsEnabled

So a given train follows a route and consists of several rows with the StopIndex indicating the order. The problem I am trying to solve is to say which stations a user can get to from a given starting station based on the train services that are available. This would be relatively straightforward BUT it is also possible to disable stops which means that a user cannot get to any destinations after that stop for that train service. It is also possible that multiple trains on different routes can share stations e.g.:

Train Service 1: A, B, C, D, E

Train Service 2: P, Q, B, C, D, R

So if a user is at B they can go to C, D, E and R but if station D is disabled on either service they can get to C only. If station E is disabled on service 1 the user can get to C, D and R.

Solving this problem is fairly straightforward within C# but I am wondering whether it can be solved elegantly and efficiently within SQL? I’m struggling to find a way, for each route, to rule out stations past a row that is not enabled.

  • 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-14T14:51:09+00:00Added an answer on May 14, 2026 at 2:51 pm

    I think I might set it up this way. Three tables:

    ROUTE
    List of routes

    STATION
    List of stations

    ROUTEPATH (or route plan?)
    Many-to-many table between route and station, including the StopIndex attribute

    Whether a station is enabled or disabled is both an attribute of an individual station (station is closed) AND an attribute of the route path (station before “this” station is closed, so “this” is also closed). That means that IsEnabled should appear in bot the STATION and ROUTEPATH tables.

    When a station is to be disabled:

    • Flag it as disabled in STATION
    • Flag it as disabled in ROUTEPATH
    • For each route containing that station, flag all stations with StopIndex greater than that station’s as disabled (these last two can be done as one update query)

    When a station is to be enabled, reverse the process.

    There will of course be problems when more than one station becomes disabled–or rather, when some but not all disabled stations become enabled again. I think it would be better to make ROUTEPATH’s attribute “IsDisabled”, and make it an integer:

    • Zero means not disabled
    • Non-zero means disabled
    • Increment it by one for each “station disabled” action
    • Decrement it by one for each “station enabled” action

    A system like this should lend itself to relatively simple queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.