Hi,
I'm trying to write a report for our branches which shows the pending (when I say pending I mean ordered but not received) POs related to jobs.
I see PMTRAN contains much of the information I want, but not all. First off PMTRAN doesn't contain the vendor itemno, though I think I could work around that if I could get passed the next issue. I'm joining PMTRAN to POPORH1 get the expected arrival date (which is an essential requirement of the report) and then I join POPORH1 to POPORL to get the order/received amounts along with the currency it was paid in.
SELECT
PMCONTS.[CONTRACT],
PMCONTS.[DESC],
PMTRAN.DOCDATE,
PMTRAN.DOCNUM,
PMPROJS.PROJECT,
PMPROJS.[DESC],
POPORL.EXPARRIVAL,
POPORH1.VDNAME,
POPORL.VENDITEMNO,
POPORL.ITEMNO,
POPORL.ITEMDESC,
POPORL.OQORDERED,
POPORL.UNITCOST,
POPORH1.CURRENCY,
POPORL.EXTENDED,
POPORL.FCEXTENDED,
POPORH1.SCURNDECML
FROM
PMCONTS
INNER JOIN
PMPROJS
ON PMCONTS.CTUNIQ = PMPROJS.CTUNIQ AND
LEFT(PMPROJS.PROJECT, 1) = '5' AND
PMCONTS.[CONTRACT] not like 'GL%'
INNER JOIN
PMTRAN
ON PMCONTS.[CONTRACT] = PMTRAN.[CONTRACT] AND
PMPROJS.PROJECT = PMTRAN.PROJECT AND
PMTRAN.MODULE = 'PO' AND
PMTRAN.COSTREV = 1
INNER JOIN
POPORH1
ON PMTRAN.DRILLDWNLK = POPORH1.PORHSEQ AND
POPORH1.ISCOMPLETE = 0
INNER JOIN
POPORL
ON POPORH1.PORHSEQ = POPORL.PORHSEQ AND
PMTRAN.[CONTRACT] = POPORL.[CONTRACT] AND
PMTRAN.PROJECT = POPORL.PROJECT
The issue I'm encountering is the replication of records when POPORL is added to the query because there's no direct key (that I know of and that's my main issue) between POPORL and PMTRAN at the line item level. I could create the query by omitting PMTRAN totally and just drill down on the CONTRACT and PROJECT fields in POPORL, however I'm not sure if that's the right way to do this. I'm looking for some insight as to whether I should abandon PMTRAN totally or if there's a link I've overlooked which will allow me to eliminate the replication (or another dumb mistake I'm making).
I'm trying to write a report for our branches which shows the pending (when I say pending I mean ordered but not received) POs related to jobs.
I see PMTRAN contains much of the information I want, but not all. First off PMTRAN doesn't contain the vendor itemno, though I think I could work around that if I could get passed the next issue. I'm joining PMTRAN to POPORH1 get the expected arrival date (which is an essential requirement of the report) and then I join POPORH1 to POPORL to get the order/received amounts along with the currency it was paid in.
SELECT
PMCONTS.[CONTRACT],
PMCONTS.[DESC],
PMTRAN.DOCDATE,
PMTRAN.DOCNUM,
PMPROJS.PROJECT,
PMPROJS.[DESC],
POPORL.EXPARRIVAL,
POPORH1.VDNAME,
POPORL.VENDITEMNO,
POPORL.ITEMNO,
POPORL.ITEMDESC,
POPORL.OQORDERED,
POPORL.UNITCOST,
POPORH1.CURRENCY,
POPORL.EXTENDED,
POPORL.FCEXTENDED,
POPORH1.SCURNDECML
FROM
PMCONTS
INNER JOIN
PMPROJS
ON PMCONTS.CTUNIQ = PMPROJS.CTUNIQ AND
LEFT(PMPROJS.PROJECT, 1) = '5' AND
PMCONTS.[CONTRACT] not like 'GL%'
INNER JOIN
PMTRAN
ON PMCONTS.[CONTRACT] = PMTRAN.[CONTRACT] AND
PMPROJS.PROJECT = PMTRAN.PROJECT AND
PMTRAN.MODULE = 'PO' AND
PMTRAN.COSTREV = 1
INNER JOIN
POPORH1
ON PMTRAN.DRILLDWNLK = POPORH1.PORHSEQ AND
POPORH1.ISCOMPLETE = 0
INNER JOIN
POPORL
ON POPORH1.PORHSEQ = POPORL.PORHSEQ AND
PMTRAN.[CONTRACT] = POPORL.[CONTRACT] AND
PMTRAN.PROJECT = POPORL.PROJECT
The issue I'm encountering is the replication of records when POPORL is added to the query because there's no direct key (that I know of and that's my main issue) between POPORL and PMTRAN at the line item level. I could create the query by omitting PMTRAN totally and just drill down on the CONTRACT and PROJECT fields in POPORL, however I'm not sure if that's the right way to do this. I'm looking for some insight as to whether I should abandon PMTRAN totally or if there's a link I've overlooked which will allow me to eliminate the replication (or another dumb mistake I'm making).