Help greatly appreciated with formatting a SQL Query
I need to select from an ARDOC table Credit Memo documents that are older than the oldest Invoice in the same table.
Both of which have a DOCBAL<>0 and for the same CUSTID.
I am basically identifying Credit Memos with DOCBAL <>0 that are older than the oldest Invoice with a DOCBAL <>0 within a CUSTID.
One document per row in the table. Table Contains both CM and IN type entries.
Credit Memos are DOCTYPE='CM'
Invoices are DOCTYPE='IN'
Here are a couple of queries I have:
Your help in formatting these to yield the results is truly appreciated:
select CustId,RefNbr,DocType,DocDate,OrigDocAmt,DocBal
from ARDoc
where DocType = 'CM'
and DocBal<>0
select CustId,RefNbr,DocType,DocDate,OrigDocAmt,DocBal
from ARDoc
where DocType = 'IN'
and DocBal<>0
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.