This is a basic sales query. I use it as a starting point when doing sales and customer reporting.
SOP unposted invoices/returns in GP; change SOP10100 to SOP30200 and SOP10200 to SOP30300 for historical.
select
a.sopnumbe,
a.ORIGNUMB,
a.docid,
a.custnmbr,
a.docdate,
a.invodate,
a.mstrnumb,
a.CNTCPRSN,
a.ShipToName,
a.ADDRESS1,
a.ADDRESS2,
a.ADDRESS3,
a.city,
a.STATE,
a.ZIPCODE,
a.PYMTRCVD,
a.SUBTOTAL,
a.FRTAMNT,
a.MISCAMNT,
a.TRDISAMT,
a.TAXAMNT,
a.DOCAMNT,
a.SHIPMTHD,
b.ITEMNMBR,
b.ITEMDESC,
b.QUANTITY,
b.NONINVEN,
b.DROPSHIP,
b.LOCNCODE,
b.UNITCOST,
b.EXTDCOST,
b.UNITPRCE,
b.XTNDPRCE,
b.MRKDNAMT
from sop10100a, sop10200 b
where a.soptype in ('3', '4') and a.sopnumbe = b.sopnumbe and a.soptype = b.soptype and VOIDSTTS = '0'