I am having a problem showing a set of data that I have got from an sql statement:
SELECT
T.Code TravelNumber,
T.Start TravelDate,
T.QuoteID PackageID
FROM Travel T
INNER JOIN Package P ON P.ID = T.QuoteID
WHERE T.CODE LIKE 'KM%' --Bus Code
AND T.Start > GETDATE() --Future Departure Dates Only
AND T.TID=302 --Type is Bus
AND P.SID <> 2560 --Status is Confirmed
ORDER BY T.QuoteID ASC
As an Example the following returns:
TravelNumber | TravelDate | PackageID
KM001 | 01/01/2007 | 1
KM002 | 07/01/2007 | 1
KM005 | 01/05/2007 | 2
KM006 | 07/05/2007 | 2
KM055 | 01/03/2007 | 3
KM056 | 07/03/2007 | 3
What I need is the data to be grouped by packageID but in order of the 1st Travel Date. As you can probably guess, the 1st Date of the package is out, and the 2nd is return.
So it needs to look like this:
TravelNumber | TravelDate | PackageID
KM001 | 01/01/2007 | 1
KM002 | 07/01/2007 | 1
KM055 | 01/03/2007 | 3
KM056 | 07/03/2007 | 3
KM005 | 01/05/2007 | 2
KM006 | 07/05/2007 | 2
I've tried so many thing to keep it simple but group by does not seem to apply here and a basic sort doesnt do anything.
Just in case it helps, there is a field in the travel table that says if the row is a departure travel. e.g. Out =1.
Please can someone shed some light on this little problem
Thanks
SELECT
T.Code TravelNumber,
T.Start TravelDate,
T.QuoteID PackageID
FROM Travel T
INNER JOIN Package P ON P.ID = T.QuoteID
WHERE T.CODE LIKE 'KM%' --Bus Code
AND T.Start > GETDATE() --Future Departure Dates Only
AND T.TID=302 --Type is Bus
AND P.SID <> 2560 --Status is Confirmed
ORDER BY T.QuoteID ASC
As an Example the following returns:
TravelNumber | TravelDate | PackageID
KM001 | 01/01/2007 | 1
KM002 | 07/01/2007 | 1
KM005 | 01/05/2007 | 2
KM006 | 07/05/2007 | 2
KM055 | 01/03/2007 | 3
KM056 | 07/03/2007 | 3
What I need is the data to be grouped by packageID but in order of the 1st Travel Date. As you can probably guess, the 1st Date of the package is out, and the 2nd is return.
So it needs to look like this:
TravelNumber | TravelDate | PackageID
KM001 | 01/01/2007 | 1
KM002 | 07/01/2007 | 1
KM055 | 01/03/2007 | 3
KM056 | 07/03/2007 | 3
KM005 | 01/05/2007 | 2
KM006 | 07/05/2007 | 2
I've tried so many thing to keep it simple but group by does not seem to apply here and a basic sort doesnt do anything.
Just in case it helps, there is a field in the travel table that says if the row is a departure travel. e.g. Out =1.
Please can someone shed some light on this little problem
Thanks