Skip to content

Instantly share code, notes, and snippets.

@Razoxane
Last active July 29, 2016 05:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Razoxane/393501e10666fca651ec to your computer and use it in GitHub Desktop.
Save Razoxane/393501e10666fca651ec to your computer and use it in GitHub Desktop.
Preferred way to suppress reversed journal entries
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