Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list all cars query...

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
hi,

the following query works out total booked days, per month, for a car booking query - but i would like the query to show all cars in the table 'courtcars'
so i can list all cars even if they dont have bookings.
at the moment it only shows cars which have a booking.

so far i have

Code:
SELECT CC.reg, month(cal.datefield), CC.carid, CBB.courtcarbookid,tran.trandesc, CC.model, COUNT(cal.datefield) AS NumDays 
FROM CourtCar AS CC 
LEFT JOIN 
(SELECT CB.bookst, CB.bookend, CB.carid, CB.courtcarbookid, CB.cusid 
FROM courtcarbook AS CB) 
AS CBB ON CC.carid = CBB.carid
LEFT JOIN cal ON cal.datefield >= CBB.Bookst 
AND cal.datefield <= CBB.Bookend 
LEFT JOIN tran ON CC.tranid = tran.tranid 
LEFT JOIN cus ON cus.cusid = CBB.cusid 
WHERE cal.datefield >= '20070101' 
AND cal.datefield <= '20071231' 
AND display = 0 
GROUP BY CC.carid, month(cal.datefield) 
ORDER BY CC.carid ASC, CC.makeid ASC, month(cal.datefield) ASC
 
think i got it

Code:
SELECT CC.reg, month(cbb.datefield), CC.carid, CBB.courtcarbookid,tran.trandesc, CC.model, COUNT(cbb.datefield) AS NumDays 
FROM CourtCar AS CC 
LEFT JOIN 
(SELECT CB.bookst, CB.bookend, CB.carid, CB.courtcarbookid, CB.cusid, cal.datefield 
FROM courtcarbook AS CB
LEFT JOIN cal ON cal.datefield >= CB.Bookst 
AND cal.datefield <= CB.Bookend 
WHERE cal.datefield >= '20070101' 
AND cal.datefield <= '20071231')
AS CBB ON CC.carid = CBB.carid
LEFT JOIN tran ON CC.tranid = tran.tranid 
LEFT JOIN cus ON cus.cusid = CBB.cusid 
AND display = 0 
GROUP BY CC.carid, month(cbb.datefield) 
ORDER BY CC.carid ASC, CC.makeid ASC, month(cbb.datefield) ASC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top