Goal: To show all property units by property rather vacant or not with renter info and summary of all payments (by each rent, late, utilities) made in a given month. eg if renter makes partial payments Do not want to show each partial but summarize into one record.
Here is as close as I can get. The challenge is if the renter makes multiple payments in one month the query returns each payment as a separate record and will not summarize all the payments into one record.
=======================================================
SELECT
ROW_NUMBER() OVER(ORDER BY r.RenterID) AS rownum,
p.PropertyID,
pu.PropertyUnitID,
r.RenterID,
p.PropertyName,
pu.PropertyUnitName,
r.RenterLastName,
SUM(rpay.RentAmountPaid) OVER(PARTITION BY rpay.RenterID) AS RentAmountPaid,
rpay.LastModifiedDate AS LMD
FROM
tblProperty p FULL OUTER JOIN
tblPropertyUnits pu ON p.PropertyID = pu.PropertyID FULL OUTER JOIN
tblRenter r ON pu.PropertyUnitID = r.PropertyUnitID FULL OUTER JOIN
tblRentPayments rpay ON r.RenterID = rpay.RenterID
WHERE
pu.PropertyID = 3 AND MONTH(rpay.LastModifiedDate) = 2
ORDER BY
p.PropertyID, pu.PropertyUnitID
========================================