Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
yaman
Posting Yak Master
213 Posts |
Posted - 2008-09-24 : 06:07:32
|
| Sir i have two tables :-1. Train Table ( Trainid , Trainname , Totalseats )2. Transactions Table ( Transactionid, Trainid, OccupiedSeat, ArrivalTime,Departuretime) Now i want to find Available Seats in a train in a Fix time .Data of table TransactionTransactionid Trainid OccupiedSeat ArrivalTime Departuretime1 2315 10 1PM 2PM2 2315 20 2PM 3PM3 2315 30 3PM 4PMHow can i find out . Yaman |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-24 : 06:15:12
|
[code]DECLARE @Train TABLE ( TrainID INT, TrainName VARCHAR(20), TotalSeats INT )INSERT @TrainSELECT 2315, 'SQLTeam', 63DECLARE @Transactions TABLE ( TransactionID INT, TrainID INT, OccupiedSeat INT, ArrivalTime DATETIME, Departuretime DATETIME ) INSERT @TransactionsSELECT 1, 2315, 10, '1PM', '2PM' UNION ALLSELECT 2, 2315, 20, '2PM', '3PM' UNION ALLSELECT 3, 2315, 30, '3PM', '4PM'DECLARE @MyTime DATETIMESET @MyTime = '1:30PM'SELECT t.TrainID, t.TrainName, t.TotalSeats, s.OccupiedSeat, t.TotalSeats - s.OccupiedSeat AS AvailableSeatsFROM @Train AS tINNER JOIN @Transactions AS s ON s.TrainID = t.TrainIDWHERE @MyTime BETWEEN s.ArrivalTime AND s.DepartureTime[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-24 : 07:21:24
|
quote: Originally posted by yaman Sir i have two tables :-1. Train Table ( Trainid , Trainname , Totalseats )2. Transactions Table ( Transactionid, Trainid, OccupiedSeat, ArrivalTime,Departuretime) Now i want to find Available Seats in a train in a Fix time .Data of table TransactionTransactionid Trainid OccupiedSeat ArrivalTime Departuretime1 2315 10 1PM 2PM2 2315 20 2PM 3PM3 2315 30 3PM 4PMHow can i find out . Yaman
does occupied seat represent the occupied seat number or is it number of occupied seats at that time? |
 |
|
|
|
|
|
|
|