Hey to all!
I've got a bit of a problem with some SQL.. just wondering if I could get some pointers. Basically, I'm writing a query in Microsoft Access to take the number of seats on a plane from one table, and create all those seats in another table. The problem i've got is the second part... from what I can work out it needs to be some kind of for/while loop. Just wondering if anyone can make the following SQL work or give me some pointers:
Psuedo code:
Actual code so far:
Cheers,
Rich
I've got a bit of a problem with some SQL.. just wondering if I could get some pointers. Basically, I'm writing a query in Microsoft Access to take the number of seats on a plane from one table, and create all those seats in another table. The problem i've got is the second part... from what I can work out it needs to be some kind of for/while loop. Just wondering if anyone can make the following SQL work or give me some pointers:
Psuedo code:
Code:
WHILE (Select latest seat from seats table where flight id==1) < (Select number of seats from the aircraft table where aircraft id==1)
INSERT each seat into the seats table.. e.g.
Seat ID | Flight ID
1 1
2 1
3 1
4 1
Actual code so far:
Code:
WHILE (SELECT TOP 1 Seats.[Seat No], Seats.[Flight ID] FROM Seats WHERE (((Seats.[Flight ID])=1)) ORDER BY Seats.[Seat No] DESC) < (SELECT Aircraft.[No of Seats], Flight.[Flight ID] FROM Aircraft INNER JOIN Flight ON Aircraft.[Aircraft ID] = Flight.[Aircraft ID] WHERE ((Flight.[Flight ID])=1))
Cheers,
Rich