Link to home
Start Free TrialLog in
Avatar of tfkcon
tfkcon

asked on

Access query follow up to question that was answered

Here is the questions:
I have an Access db with a sample file containing invoices paid.  
I need to write a report that groups payment of equal amounts (Use GrossAmt) for each vendor together.

Ignore the sign (positive or negative) of the amount. Ignore groups with only one record.
For each vendor show a group header containing the vendor number and name.

For example if the GrossAmt is $100 in one record and the GrossAmt is $-100 in another record treat that as a match.

Here is the answer that I wanted some clarification on the sql:
SELECT ApTest.VenNum, Abs(ApTest.GrossAmt) AS [Gross Amount Duplicate], ApVenTest.VenName, ApTest.InvNum AS InvNum, ApTest.DueDte, ApTest.PaidDte
FROM ApTest INNER JOIN ApVenTest ON ApTest.VenNum = ApVenTest.VenNum
GROUP BY ApTest.VenNum, ApTest.GrossAmt, ApVenTest.VenName, ApTest.InvNum, ApTest.DueDte, ApTest.PaidDte
HAVING (((ApTest.VenNum) In (SELECT [VenNum] FROM [ApTest] As Tmp GROUP BY [VenNum], Abs([GrossAmt]) HAVING Count(*)>1  And Abs([GrossAmt]) = Abs([ApTest].[GrossAmt]))))
ORDER BY ApTest.VenNum, Abs(ApTest.GrossAmt);
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

the Abs() function converts (- values) to + values.. is that what you want to know?
Avatar of tfkcon
tfkcon

ASKER

Im more concerned with the part of the query where you are using the "IN"
Avatar of tfkcon

ASKER

Or if you could just explain your Having Clause...Im a little confused how you came up with it.
that part...(in short)

it is looking for [VenNum] that is having a count >1, meaning duplicate or more
with (also) duplicate (same) [GrossAmt]

Avatar of tfkcon

ASKER

Im gonna give you the points but could that have been done in the first Having clause?
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hope you understood the explanation.. i am not good at picking the correct word to explain things.. sorry ( english is not my first language) :-(