Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2012
»
SQL Server 2012 - T-SQL
»
query for routing
query for routing
Rate Topic
Display Mode
Topic Options
Author
Message
fbrewer
fbrewer
Posted Wednesday, January 02, 2013 3:28 PM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, January 09, 2013 10:32 PM
Points: 4,
Visits: 9
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
dwain.c
dwain.c
Posted Wednesday, January 02, 2013 6:35 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 6:03 AM
Points: 2,345,
Visits: 3,191
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.
No loops! No CURSORs! No RBAR! Hoo-uh!
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?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1402137
fbrewer
fbrewer
Posted Wednesday, January 02, 2013 7:45 PM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, January 09, 2013 10:32 PM
Points: 4,
Visits: 9
dwain,
Thanks for your post. I will consume it over the next few days and will report back.
Post #1402150
dwain.c
dwain.c
Posted Wednesday, January 09, 2013 6:31 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 6:03 AM
Points: 2,345,
Visits: 3,191
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.
No loops! No CURSORs! No RBAR! Hoo-uh!
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?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1405105
fbrewer
fbrewer
Posted Wednesday, January 09, 2013 10:35 PM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, January 09, 2013 10:32 PM
Points: 4,
Visits: 9
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.