Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

query for routing Expand / Collapse
Author
Message
Posted Wednesday, January 2, 2013 3:28 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 8, 2014 10:44 AM
Points: 4, Visits: 10
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.
Post #1402099
Posted Wednesday, January 2, 2013 6:35 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:45 AM
Points: 3,614, Visits: 5,227
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.

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.

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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1402137
Posted Wednesday, January 2, 2013 7:45 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 8, 2014 10:44 AM
Points: 4, Visits: 10
dwain,

Thanks for your post. I will consume it over the next few days and will report back.
Post #1402150
Posted Wednesday, January 9, 2013 6:31 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:45 AM
Points: 3,614, Visits: 5,227
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1405105
Posted Wednesday, January 9, 2013 10:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 8, 2014 10:44 AM
Points: 4, Visits: 10
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
Post #1405176
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse