Last active
July 29, 2016 05:00
-
-
Save Razoxane/393501e10666fca651ec to your computer and use it in GitHub Desktop.
Preferred way to suppress reversed journal entries
This file contains hidden or 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
SELECT je.* | |
FROM journal_entry AS je ON a.assetID = je.assetID | |
AND je.reference IN ('OPEN','AQ','DR') | |
AND CASE WHEN je.reference = 'DR' THEN je.description LIKE 'Direct Reinvestment%' ELSE 1=1 END | |
AND je.entryType = 'debit' | |
AND IFNULL(je.assetID,0) > 0 | |
/* some join conditions for the je table, can vary depending on what's being joined (account or asset) */ | |
LEFT JOIN journal_entry AS aj ON je.fundID = aj.fundID | |
AND je.memberAccountID = aj.memberAccountID | |
AND je.entryID = aj.reverseEntryID | |
/* must join on all these columns to optimise performance */ | |
WHERE je.fundID = '$fundID' | |
/* here are the two anti-join conditions */ | |
AND IFNULL(aj.reverseEntryID, 0) = 0 | |
AND je.reference NOT LIKE 'r%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment