Link to home
Start Free TrialLog in
Avatar of mike247
mike247Flag for United States of America

asked on

sql query - last invoice date where invoice is greater than zero

How can I make this query return not just the max invoice date, but latest invoice date where the invoice is greater than zero?  Ignore zero dollar invoices.  The field is Docamnt for invoice amount.

SELECT DISTINCT t1.CUSTNMBR, t2.max_GLPOSTDT
FROM            dbo.SOP30200 AS t1 INNER JOIN
                             (SELECT        CUSTNMBR, MAX(GLPOSTDT) AS max_GLPOSTDT
                               FROM            dbo.SOP30200
                               GROUP BY CUSTNMBR) AS t2 ON t1.CUSTNMBR = t2.CUSTNMBR


So I want to find the last invoice date for each customer where the invoice is greater than zero.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg 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
Avatar of mike247

ASKER

works great.  Thanks.