Click here to Skip to main content
16,006,749 members
Home / Discussions / Database
   

Database

 
GeneralI'm going crazy!!!!!!!! Pin
LukeV10-Dec-02 3:44
LukeV10-Dec-02 3:44 
GeneralRe: I'm going crazy!!!!!!!! Pin
Rob Graham12-Dec-02 4:25
Rob Graham12-Dec-02 4:25 
GeneralRe: I'm going crazy!!!!!!!! Pin
LukeV12-Dec-02 7:53
LukeV12-Dec-02 7:53 
GeneralRe: I'm going crazy!!!!!!!! Pin
Rob Graham12-Dec-02 11:46
Rob Graham12-Dec-02 11:46 
GeneralRe: I'm going crazy!!!!!!!! Pin
Murat YILDIZ26-Dec-02 5:19
Murat YILDIZ26-Dec-02 5:19 
GeneralRe: Get number of records Pin
Daniel Turini10-Dec-02 1:32
Daniel Turini10-Dec-02 1:32 
GeneralRe: Get number of records Pin
Steve McLenithan10-Dec-02 1:55
Steve McLenithan10-Dec-02 1:55 
GeneralA tricky Sql statement Pin
DamienL9-Dec-02 23:51
DamienL9-Dec-02 23:51 
Hi all,
I need your help

This Sql statement calulates journey details after you enter your start station, end station and a time to travel after. It calculates your journey when the two stations you enter are not on the same 'route'.

I use 3 tables out of my database for this query:
*=Primary Key & -> are the relationships

StopsAt: Follows: Route:
JourneyNumber-> <-JourneyNumber <-*RouteNumber
StationName *RouteNumber->
Time
*AutoNumber

An example is:
Input- Crofton Rd to Loft Rd, after 12:25

Output:
Crofton Rd 12:30 Abbey Rd 12:46 Route:46A
& connect to>
Essex Rd 12:49 Loft Rd 12:52 Route:123A
....
Crofton Rd 12:30 Clare Rd 12:46 Route:46A
& connect to>
Sorrow Rd 12:49 Loft Rd 12:52 Route:123A
...and every other possible route there is

The problem: the query outputs all the possible connecting routes. I want it to pick one journey from Crofton Rd to X and from X to Loft Rd. So not list every possible route from Crofton road to Loft Rd.

I think I have to design another clause in the FROM part to account for Third.StationName and Fourth.StionName and join these up to the 'Follows' and 'Route' tables. I tried many things and cannot get it.
There are 4 copies of the StopsAt table made & I guess I have to make another copy of the 'Follows' and 'Route' table and Inner Join these.

I wrote the Sql statement like this so it's easier to read.

Please help me.

Sql= "
SELECT DISTINCT
First.StationName AS Begin,
First.Time AS StartTime,
Second.StationName AS SecondStop,
Second.Time AS ArriveTime,
Route.RouteNumber AS RouteNumber1,

Third.StationName AS ThirdStop,
Third.Time AS StartTime2,
Fourth.StationName AS Destination,
Fourth.Time AS DestinationTime,
Route2.RouteNumber AS RouteNumber2

FROM
Route AS Route2,
StopsAt AS Third,
StopsAt AS Fourth,

StopsAt AS Second
INNER JOIN ((
StopsAt AS First INNER JOIN Follows
ON First.JourneyNumber = Follows.JourneyNumber)
INNER JOIN
Route
ON Follows.RouteNumber = Route.RouteNumber)
ON Second.JourneyNumber = Follows.JourneyNumber

WHERE
First.StationName = [user input]
AND Fourth.StationName = [user input]
AND Third.Time > Second.Time
AND Second.Time > First.Time
AND Fourth.Time > Third.Time
AND First.JourneyNumber = Second.JourneyNumber
AND Third.JourneyNumber = Fourth.JourneyNumber
AND First.Time > [user input]


Damien
QuestionHow can I add a string that has a single quote character in it? Pin
Bart-Man9-Dec-02 11:28
Bart-Man9-Dec-02 11:28 
AnswerRe: How can I add a string that has a single quote character in it? Pin
David Salter9-Dec-02 11:56
David Salter9-Dec-02 11:56 
GeneralRe: How can I add a string that has a single quote character in it? Pin
Bart-Man10-Dec-02 3:36
Bart-Man10-Dec-02 3:36 
AnswerRe: How can I add a string that has a single quote character in it? Pin
Paul Watson10-Dec-02 0:03
sitebuilderPaul Watson10-Dec-02 0:03 
GeneralRe: How can I add a string that has a single quote character in it? Pin
Bart-Man10-Dec-02 3:37
Bart-Man10-Dec-02 3:37 
AnswerRe: How can I add a string that has a single quote character in it? Pin
Daniel Turini10-Dec-02 1:40
Daniel Turini10-Dec-02 1:40 
GeneralRe: How can I add a string that has a single quote character in it? Pin
Bart-Man10-Dec-02 3:39
Bart-Man10-Dec-02 3:39 
GeneralRe: How can I add a string that has a single quote character in it? Pin
David Salter11-Dec-02 10:37
David Salter11-Dec-02 10:37 
GeneralRe: How can I add a string that has a single quote character in it? Pin
Daniel Turini11-Dec-02 11:49
Daniel Turini11-Dec-02 11:49 
GeneralRecord Number ... Pin
RJS9-Dec-02 7:41
RJS9-Dec-02 7:41 
GeneralRe: Record Number ... Pin
David Salter9-Dec-02 10:04
David Salter9-Dec-02 10:04 
GeneralRe: Record Number ... Pin
Not Active9-Dec-02 14:33
mentorNot Active9-Dec-02 14:33 
GeneralRe: Record Number ... Pin
Daniel Turini10-Dec-02 1:43
Daniel Turini10-Dec-02 1:43 
GeneralPartial Search Pin
Sarvesvara (BVKS) Dasa9-Dec-02 1:25
Sarvesvara (BVKS) Dasa9-Dec-02 1:25 
GeneralRe: Partial Search Pin
Not Active9-Dec-02 2:09
mentorNot Active9-Dec-02 2:09 
GeneralRe: Partial Search Pin
Sarvesvara (BVKS) Dasa9-Dec-02 2:39
Sarvesvara (BVKS) Dasa9-Dec-02 2:39 
GeneralRe: Partial Search Pin
David Salter9-Dec-02 3:00
David Salter9-Dec-02 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.