Hi
I'm doing a winform app with sql server 2008 in VS2008, where a company has parking lots for rent. It works like this, when a car arrives it gets a date of arrival. If this car never has been invoiced before my sql statement should get the arrival date. If it has been invoiced before it should take the highest date (Max(invoiceday)) and only return that record/car.
In my case it works fine until I have done invoice no 2, then it returns both records for that car instead of just the highest.
"SELECT * FROM Cars LEFT JOIN Invoice ON Cars.carId=Invoice.carId WHERE Cars.Arrival <= '" & date & "' AND Invoice.Invoiceday IS NULL OR (SELECT MAX(Invoice.Invoiceday) FROM Invoice WHERE Invoice.carId=Cars.carId) <= '" & date & "' "

2 answers
why you do not do change statement using
order by Invoiceday desc (that will give you order from highest date)
and after limit result on one row?
just an idea:)
answered one year ago by:
556
I haven't tested it, but this should get what you want:
answered one year ago by:
2499