Last active
March 24, 2017 15:00
-
-
Save apeterson-BFI/5eb496c7ac66305743e47af3cb32bc21 to your computer and use it in GitHub Desktop.
Update receipt status on Void Check - GMS2
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
/* update Receipts on Check to O, X, or V */ | |
UPDATE r1 | |
SET [Status] = | |
CASE | |
WHEN MaxSeq.MaxSeqNo % 2 = 1 THEN -- ends in a void | |
CASE r1.SequenceNo | |
WHEN MaxSeq.MaxSeqNo THEN 'V' | |
WHEN MaxSeq.MaxSeqNo - 1 THEN 'V' | |
ELSE 'X' | |
END | |
WHEN MaxSeq.MaxSeqNo % 2 = 0 THEN | |
CASE r1.SequenceNo | |
WHEN MaxSeq.MaxSeqNo THEN 'O' | |
ELSE 'X' | |
END | |
END | |
FROM Receipt r1 | |
INNER JOIN Payable on r1.TransactionKey = Payable.ReceiptTKey | |
INNER JOIN PayableCheck ON Payable.PayableID = PayableCheck.PayableID | |
INNER JOIN | |
( | |
SELECT r2.Receipt_ID, MAX(r2.SequenceNo) as MaxSeqNo | |
FROM Receipt r2 | |
GROUP BY Receipt_ID | |
) MaxSeq ON r1.Receipt_ID = MaxSeq.Receipt_ID | |
WHERE PayableCheck.CheckID = @checkID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment