wysiwygGER01
Programmer
Hi,
My SQL statement returns a few duplicate lines and I can't figure out how to improve it.
I narrowed my problem down to the join between my view "PO" and my table pmtran.
The view "PO" looks like this and returns:
SELECT porcpl.ponumber,porcph1.vdname, porcpl.venditemno
FROM porcpl
INNER JOIN porcph1 ON porcph1.ponumber = porcpl.ponumber
WHERE porcpl.ccategory = '110' AND PORCPL.PONUMBER like 'PO003306'
ponumber | vdname | venditemno
10 | testvendor | 123
10 | testvendor | 456
This is what I want to see. This is correct.
My final statement looks like this and returns the following:
SELECT PM.CATEGORY, PM.RESOURCE, pm.TRANSQTY, po.vendditemno
FROM PMTRAN AS PM
LEFT JOIN PO ON PM.refdoc = po.ponumber
AND PM.CATEGORY = '110'
WHERE PM.fmtcontno = 'P-09-001-00'
AND PM.project = '120'
AND PM.costrev = '1'
AND PM.doctype IN ('7', '8', '9', '17', '18')
ORDER BY PM.RESOURCE;
category | resource | quantity | vendditemno
100 | 98 | 1 | NULL
100 | 99 | 3 | NULL
110 | NULL | 1 | 123
110 | NULL | 1 | 456<---this line is
redundant
110 | NULL | 2 | 123<---this line is
redundant
110 | NULL | 2 | 456
What I'd like it to return is:
category | resource | quantity | vendditemno
100 | 98 | 1 | NULL
100 | 99 | 3 | NULL
110 | NULL | 1 | 123
110 | NULL | 2 | 456
Can this be done at all?
My SQL statement returns a few duplicate lines and I can't figure out how to improve it.
I narrowed my problem down to the join between my view "PO" and my table pmtran.
The view "PO" looks like this and returns:
SELECT porcpl.ponumber,porcph1.vdname, porcpl.venditemno
FROM porcpl
INNER JOIN porcph1 ON porcph1.ponumber = porcpl.ponumber
WHERE porcpl.ccategory = '110' AND PORCPL.PONUMBER like 'PO003306'
ponumber | vdname | venditemno
10 | testvendor | 123
10 | testvendor | 456
This is what I want to see. This is correct.
My final statement looks like this and returns the following:
SELECT PM.CATEGORY, PM.RESOURCE, pm.TRANSQTY, po.vendditemno
FROM PMTRAN AS PM
LEFT JOIN PO ON PM.refdoc = po.ponumber
AND PM.CATEGORY = '110'
WHERE PM.fmtcontno = 'P-09-001-00'
AND PM.project = '120'
AND PM.costrev = '1'
AND PM.doctype IN ('7', '8', '9', '17', '18')
ORDER BY PM.RESOURCE;
category | resource | quantity | vendditemno
100 | 98 | 1 | NULL
100 | 99 | 3 | NULL
110 | NULL | 1 | 123
110 | NULL | 1 | 456<---this line is
redundant
110 | NULL | 2 | 123<---this line is
redundant
110 | NULL | 2 | 456
What I'd like it to return is:
category | resource | quantity | vendditemno
100 | 98 | 1 | NULL
100 | 99 | 3 | NULL
110 | NULL | 1 | 123
110 | NULL | 2 | 456
Can this be done at all?