rabbit75
Programmer
- Aug 15, 2002
- 30
Hi,
I have this SELECT that is almost working, but the LEFT OUTER JOIN is giving me a problem:
The problem is, sometimes there are records in icpric that meet both the conditions in the LEFT OUTER JOIN:
((icpric.custno = artran.custno AND icpric.item=artran.item) OR
(icpric.item=artran.item AND icpric.popt='I' AND icpric.psched=arcust.pricecode)). This is correct, there can be 2 records, each one satisfies one condition. I am getting both records if both conditions are met. I only need the first record. Should I be using a join or something else?
I have this SELECT that is almost working, but the LEFT OUTER JOIN is giving me a problem:
Code:
SELECT artran.invno, 'C' AS source, artran.item, artran.custno, artran.invdte,
artran.extprice, artran.salesmn, artran.price, artran.qtyshp, artran.arstat,
artran.artype, arcust.company, icitem.itmdesc,
icitem.plinid, icitem.itmclss, icitem.code, icitem.comcode, icitem.price AS itemprice,
icitem.ruitem, arcust.terr, arcust.pricecode, armast.cshipno,
icitem.sunmsid, icitem.weight, 0 as unitpr1
FROM artran JOIN arcust ON (arcust.custno = artran.custno)
JOIN armast ON (armast.invno = artran.invno)
JOIN icitem ON (icitem.item = artran.item)
LEFT OUTER JOIN icpric ON ((icpric.custno = artran.custno AND icpric.item=artran.item) OR
(icpric.item=artran.item AND icpric.popt='I' AND icpric.psched=arcust.pricecode))
WHERE artran.invdte >= @lc_beg_invdte
AND artran.invdte <= @lc_end_invdte AND artran.arstat <> 'V'
AND artran.currhist <> 'X'
The problem is, sometimes there are records in icpric that meet both the conditions in the LEFT OUTER JOIN:
((icpric.custno = artran.custno AND icpric.item=artran.item) OR
(icpric.item=artran.item AND icpric.popt='I' AND icpric.psched=arcust.pricecode)). This is correct, there can be 2 records, each one satisfies one condition. I am getting both records if both conditions are met. I only need the first record. Should I be using a join or something else?