Hi Everyone,
I'm trying to extract data from a general ledger system where I need to select a full journal entry which is comprised of several lines based on criteria of at least one line item in an account in an Income Statement range that meets a credit amount value as well as criteria for the other account that may have hit the Income Statement as a debit amount value. I've tried using the EXISTS clause but can't seem to get it quite right to return the full journal entry where the 2 conditions are met. Here's my query:
SELECT c.GLDOC, c.LineSeqNum, c.GLAmount, c.GLPeriod, c.GLAcctNum, c.AcctDescr
FROM Corp as C
Where
Exists (Select * from Corp WHERE (c.Gldoc = corp.Gldoc)
AND
((cint(GLAcctNum) Between 4000 AND 9999) AND GLAmount <=-350000)
AND
Exists (Select * from Corp WHERE (c.Gldoc = corp.Gldoc)
AND
((cint(GLAcctNum) NOT Between 0 AND 2999) AND GLAmount >0)
))
Order by GLDOC, CINT(LineSeqNum);
I can't get the entire journal entry line items to return. For instance I have one entry that is comprised of 73 lines but when I run the above query it won't return the entire entry, it only gives me a subset of the lines.
Any help is much appreciated
I'm trying to extract data from a general ledger system where I need to select a full journal entry which is comprised of several lines based on criteria of at least one line item in an account in an Income Statement range that meets a credit amount value as well as criteria for the other account that may have hit the Income Statement as a debit amount value. I've tried using the EXISTS clause but can't seem to get it quite right to return the full journal entry where the 2 conditions are met. Here's my query:
SELECT c.GLDOC, c.LineSeqNum, c.GLAmount, c.GLPeriod, c.GLAcctNum, c.AcctDescr
FROM Corp as C
Where
Exists (Select * from Corp WHERE (c.Gldoc = corp.Gldoc)
AND
((cint(GLAcctNum) Between 4000 AND 9999) AND GLAmount <=-350000)
AND
Exists (Select * from Corp WHERE (c.Gldoc = corp.Gldoc)
AND
((cint(GLAcctNum) NOT Between 0 AND 2999) AND GLAmount >0)
))
Order by GLDOC, CINT(LineSeqNum);
I can't get the entire journal entry line items to return. For instance I have one entry that is comprised of 73 lines but when I run the above query it won't return the entire entry, it only gives me a subset of the lines.
Any help is much appreciated