hi,
i have a car booking system that stores the booking start and end dates along with car/cus details.
now i need to make a report that shows the cars booking efficiency [daysbooked/daysofmonth]
i am having issues with vehicles that the booking starts in one month and end in another month.
i can get the number of days between the start and enddate using datediff in my sql but this doesnt take into account the 'long' bookings - i dont think i can solve this using just sql - any advice welcome
so far...
sql
asp -
i have a car booking system that stores the booking start and end dates along with car/cus details.
now i need to make a report that shows the cars booking efficiency [daysbooked/daysofmonth]
i am having issues with vehicles that the booking starts in one month and end in another month.
i can get the number of days between the start and enddate using datediff in my sql but this doesnt take into account the 'long' bookings - i dont think i can solve this using just sql - any advice welcome
so far...
sql
Code:
SELECT CC.reg, CBB.bookst, CBB.bookend, CC.carid, CBB.courtcarbookid,tran.trandesc, CC.model,
case when month( CBB.bookst ) <> month( CBB.bookend )then concat(sum(datediff( makedate( month( CBB.bookend ), 1 ), CBB.bookst )+ 1)) else concat(sum(datediff( CBB.bookend, CBB.bookst )+ 1)) end as days,
month(CBB.bookst) as month, count(cc.carid) as count
FROM courtcar AS CC
LEFT JOIN (SELECT CB.bookst, CB.bookend, CB.carid, CB.courtcarbookid, CB.cusid FROM courtcarbook
AS CB
WHERE (cb.bookst BETWEEN '20070101' AND '20071231')
OR (cb.bookend BETWEEN '20070101' AND '20071231')
OR (cb.bookst <= '20070101') AND (cb.bookend >= '20071231'))
AS CBB ON CC.carid = CBB.carid
LEFT JOIN tran ON CC.tranid = tran.tranid
LEFT JOIN cus ON cus.cusid = CBB.cusid
WHERE display = 0
GROUP BY CC.carid, month(CBB.bookst)
ORDER BY CC.carid ASC, CC.makeid ASC, month(CBB.bookst) ASC
asp -
Code:
<%' 1st week
Response.Write("<table border=0 cellpadding=4 cellspacing=1>")
Response.Write("<tr>")
Response.Write("<td colspan =4 class = courtcarhead>Vehicle</td>")
for i=0 to DateDiff("m",dStartDate,dEndDate)
daydate = (dateadd("m",i,dStartDate))
daynumshort = Month(daydate)
monthtext = (MonthName(daynumshort,true))
dayshort = formatDate ("%M",(daynumshort))
dayshortsuf = daySuff(daynumshort)
Response.Write "<td class = courtcarhead>" &monthtext& "</td>"
next
Response.Write("</tr>")
sCurrentReg = ""
recCount = 0
'for j=0 to DateDiff("m",dStartDate,dEndDate)
for j=0 to UBound(aBookings,2)
recCount = recCount + 1
bgcolor = "#00cc66"
' Display alternate color for rows
If recCount Mod 2 <> 0 Then
bgcolor = "#cccccc"
End If
sCurrentReg = aBookings(0,j)
sTran = aBookings(5,j)
carid = aBookings(3,j)
sMod = aBookings(6,j)
Response.Write("<tr bgcolor="& bgcolor & ">")
Response.Write "<td class = courtcarrowcount><img src=""images/cariconsml.gif"" border=0>"&(recCount)& "</td>"
Response.Write "<td class = courtcarreg>" &(sCurrentReg) & "</td>"
Response.Write "<td class = mfitsml nowrap=nowrap>" &(sMod)& "</td>"
Response.Write "<td class = mfitsml>" &(sTran)& "</td>"
for i=0 to DateDiff("m",dStartDate,dEndDate)
dCurrDate = DateAdd("m", i, dStartDate)
freestr = "<td class = courtcarfree width=120 align=center>0</td>"
'CC.reg, CBB.bookst, CBB.bookend, CC.carid, CBB.courtcarbookid,tran.trandesc, CC.model, case when month( CBB.bookst ) <> month( CBB.bookend )then concat(sum(datediff( makedate( month( CBB.bookend ), 1 ), CBB.bookst )+ 1)) else concat(sum(datediff( CBB.bookend, CBB.bookst )+ 1)) end as days, month(CBB.bookst) as month
if isnull(aBookings(1,j)) or isnull(aBookings(2,j)) then
response.Write(freestr)
else
if datediff("m",dCurrDate,(aBookings(1,j))) <= 0 and _
datediff("m", dCurrDate,(aBookings(2,j))) >= 0 then
'lname = (aBookings(0,j))
'lname = Left(lname, 6)
monthbook = (aBookings(7,j))
courtcarbookid = (aBookings(4,j))
response.Write "<td class = courtcarlname width=120 align=center>" & monthbook &"</td>"
else
if ubound(abookings,2) >= j+1 then
if aBookings(0,j+1) = sCurrentReg then
if datediff("m", dCurrDate , aBookings(2,j)) <= 0 then
j = j + 1
i = i - 1
else
response.Write(freestr)
end if
else
response.Write(freestr)
end if
else
response.Write(freestr)
end if
end if
end if
next
Response.Write("</tr>")
Next
Response.Write("</table>")
%>