I am working with an equipment reservation system and need to calculate days that the equipment is being rented for so I can multiply it by the total cost per day of each reservation, then total the cost for all reservations in the query. The equipment pickup date and return date are stored in separate fields as yyyy/mm/dd 00:00:00.000 (no entries contain a time other than 00:00:00.000), there is also fields for pickup AM/PM and return AM/PM. If the pickup date is in the PM then that day does not count as a day, if the return date is in the AM then it does not count as a day. Ideally I would like to use the query below to get to my end goal, however it calculates the number of days as too many.
SELECT
SUM(TOTAL*DATEDIFF(day,PICKUPDT,RETURNDT))
FROM
RENTAL
WHERE
AGENTCODE = '$AGENT' AND
PICKUPDT >= '06/01/2013' AND
RETURNDT <= '06/01/2014' AND
PAIDOUT = '1' )
The above is nested within the whole query that I am running. The TOTAL field is the cost per day of rental. I need a way to accurately count the number of days the consumer will be charged for. I appreciate any help that can be given on the topic. This is my first question here and apologize in for any mistakes I made.
The finished screen I am working towards can be seen here: