Created
June 19, 2010 12:36
-
-
Save skorfmann/444861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Selects all contracts, which aren't billed yet*/ | |
SET @start_date = '2010-06-01', @end_date = '2010-06-30'; | |
SET @month = MONTH(CURDATE()), @year = YEAR(CURDATE()); | |
SELECT c.id, c.start_date, c.end_date, IF(tmp.id IS NULL, 'Billable', 'Not Billable') | |
FROM contracts c | |
LEFT JOIN ( | |
SELECT r.id, r.contract_id | |
FROM receivables r LEFT JOIN billing_cycles b ON r.billing_cycle_id = b.id | |
WHERE b.month = @month AND b.year = @year | |
) tmp ON c.id = tmp.contract_id | |
WHERE (@start_date BETWEEN c.start_date AND c.end_date) OR | |
(c.start_date BETWEEN @start_date AND @end_date); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment