mjcmkrsr
Technical User
- Nov 30, 2010
- 840
Hi,
This is a students home booking app and I try to find the non booked periods.
The data looks like this
SELECT cHCode, dEntry, dExit, cName .... into ... vFreeRooms. The result is ordered by cHCode, dExit
1107.05 1/12/2013 15/12/2013 xxxxx
1107.05 1/1/2014 31/1/2014 xxxxx
1107.05 1/2/2014 28/2/2014 xxxxx
1107.05 16/3/2014 31/3/2014 xxxxx
and I need these results - the dates a room is booked followed by the non booked period
1107.05 1/12/2013 15/12/2013 16/12/2013 - 31/12/2013
1107.05 1/2/2014 28/2/2014 1/3/2014 - 15/3/2014
1107.05 16/3/2014 31/3/2014 1/4/2014 -
I achieve this thru the code below, which I consider not very elegant. Is there a sql command which would produce the same result. Any hint is appreciated.
btw oApp.dBofMonth is the first day of the actual month
Thks
MK
This is a students home booking app and I try to find the non booked periods.
The data looks like this
SELECT cHCode, dEntry, dExit, cName .... into ... vFreeRooms. The result is ordered by cHCode, dExit
1107.05 1/12/2013 15/12/2013 xxxxx
1107.05 1/1/2014 31/1/2014 xxxxx
1107.05 1/2/2014 28/2/2014 xxxxx
1107.05 16/3/2014 31/3/2014 xxxxx
and I need these results - the dates a room is booked followed by the non booked period
1107.05 1/12/2013 15/12/2013 16/12/2013 - 31/12/2013
1107.05 1/2/2014 28/2/2014 1/3/2014 - 15/3/2014
1107.05 16/3/2014 31/3/2014 1/4/2014 -
I achieve this thru the code below, which I consider not very elegant. Is there a sql command which would produce the same result. Any hint is appreciated.
btw oApp.dBofMonth is the first day of the actual month
Code:
SCAN
dDateOut = dExit
cRoom1 = cHCode
SKIP
dDateIn = dEntry
cRoom2 = cHCode
SKIP -1
IF cRoom1 = cRoom2
IF dDateOut + 1 = dDateIn
DELETE NEXT 1
ELSE
IF dDateIn <= oApp.dBofMonth(DATE())
DELETE NEXT 1
ELSE
REPLACE vFreeRooms.cName WITH DTOC(dDateOut + 1) +" - "+ DTOC(dDateIn - 1)
ENDIF
ENDIF
ELSE
REPLACE vFreeRooms.cName WITH DTOC(dDateOut + 1) +" - "
ENDIF
ENDSCAN
Thks
MK