Created
June 27, 2016 16:14
-
-
Save barbeau/45ccc0c16b0e1ff90d1fa616d2ca3538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT cps.vehicle_id AS vehicle, v.loc_y AS latitude, v.loc_x AS longitude, v.vehicle_position_date_time AS time, v.predicted_deviation * - 60 AS delay, v.average_speed AS speed, v.heading AS bearing, | |
cps.current_route_id AS route, LEFT(t.trip_id_external, LEN(t.trip_id_external) - 3) AS trip, bsp.bs_id AS stop, bsp.bs_seq AS sequence | |
FROM dbo.current_performance_status AS cps WITH (NOLOCK) INNER JOIN | |
dbo.VEHICLE AS v ON cps.vehicle_id = v.vehicle_id INNER JOIN | |
dbo.trip AS t ON cps.trip_id = t.trip_id AND cps.sched_version = t.sched_version INNER JOIN | |
dbo.vehicle_schedule AS vs ON cps.sched_version = vs.sched_version INNER JOIN | |
dbo.booking AS b ON vs.booking_id = b.booking_id INNER JOIN | |
dbo.trip_timepoint AS ctp ON cps.trip_id = ctp.trip_id AND cps.tp_id = ctp.tp_id AND cps.sched_version = ctp.sched_version AND DATEDIFF(n, ctp.eta, cps.sched_time) % 1440 = 0 INNER JOIN | |
dbo.bus_stop_pattern AS bsp ON b.booking_num = bsp.booking_num AND cps.current_route_id = bsp.route_id AND cps.direction_code_id = bsp.direction_code_id AND t.variation = bsp.variation AND | |
ctp.seq_num = bsp.tp_seq | |
WHERE (cps.vehicle_id <> 0) AND (v.logon_state = 1) AND (cps.transit_date_time = | |
(SELECT MAX(transit_date_time) AS Expr1 | |
FROM dbo.current_performance_status)) AND (v.predicted_deviation <> 63) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment