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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem

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 Transaction
Transactionid Trainid OccupiedSeat ArrivalTime Departuretime
1 2315 10 1PM 2PM
2 2315 20 2PM 3PM
3 2315 30 3PM 4PM


How 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 @Train
SELECT 2315, 'SQLTeam', 63

DECLARE @Transactions TABLE
(
TransactionID INT,
TrainID INT,
OccupiedSeat INT,
ArrivalTime DATETIME,
Departuretime DATETIME
)

INSERT @Transactions
SELECT 1, 2315, 10, '1PM', '2PM' UNION ALL
SELECT 2, 2315, 20, '2PM', '3PM' UNION ALL
SELECT 3, 2315, 30, '3PM', '4PM'

DECLARE @MyTime DATETIME

SET @MyTime = '1:30PM'

SELECT t.TrainID,
t.TrainName,
t.TotalSeats,
s.OccupiedSeat,
t.TotalSeats - s.OccupiedSeat AS AvailableSeats
FROM @Train AS t
INNER JOIN @Transactions AS s ON s.TrainID = t.TrainID
WHERE @MyTime BETWEEN s.ArrivalTime AND s.DepartureTime[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

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 Transaction
Transactionid Trainid OccupiedSeat ArrivalTime Departuretime
1 2315 10 1PM 2PM
2 2315 20 2PM 3PM
3 2315 30 3PM 4PM


How can i find out .



Yaman


does occupied seat represent the occupied seat number or is it number of occupied seats at that time?
Go to Top of Page
   

- Advertisement -