query for routing

  • I have a table called flights with columns: fltNum, departureCity, depTime, arrivalCity, arrTime

    I want to query flights and produce an out put table that depicts the routing from a takeoff city and a land city.

    I will designate a no earlier than takeoff time, and a no later than land time. I will also designate a minimum of 30 minutes between connections, and a maximum of 3 flights.

    The output row header is:

    flt depCity 1 depTime 1 arrCity 1 arrCity 1 flt 2 depCity 2 depTime 2 arrCity 2 arrCity 2 ............ arrCity 3

    The output will display non-stop flights, 2-flight routings, and 3-flight routings

    Any suggestions of creating the query are appreciated.

  • To get a working query out of the volunteers on this forum, you'll need to provide more in the way of DDL and consumable sample data. This article explains how: Forum Etiquette: How to post data/code on a forum to get the best help[/url].

    But I may be able to help you out a bit. Take a look at this recent article: Departures from Origins and Arrivals at Destinations[/url].

    The data structures should be quite similar and it is quite likely that some of the queries may be adaptable to your needs. Note that it is just a starting point though. The article clearly states that it is not meant to be the all singing, all dancing solution to the problem. For example, it doesn't provide the query to generate connecting flights as you've advised you wanted, however it is very likely to be possible to generate that from the data structure provided.

    I should also mention that the data structure you've proposed is going to be incomplete on several points, but reading the article should illuminate at least some of these.

    Let me know if this helps.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain,

    Thanks for your post. I will consume it over the next few days and will report back.

  • fbrewer (1/2/2013)


    dwain,

    Thanks for your post. I will consume it over the next few days and will report back.

    I was just wondering if you had any luck with this.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • Dwain,

    I have an initial stab at an algorithm for my particular purpose, but unfortunately, I have too many other responsibilities to move this forward at this time.

    I will definately share my work when I have done so.

    Thanks for asking

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

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