on 01-24-2019 6:06 PM
Experts,
I need to add the Segment Details to a query and are getting duplicate lines on this query.... Results are attached.
Your assistance would be most welcome!
SELECT T0.[DocNum], T0.[CtlAccount], T1.[AcctCode], T3.[SegmentId], T3.[Code], T3.[Name]
FROM OPCH T0
INNER JOIN PCH1 T1 ON T0.[DocEntry] = T1.[DocEntry]
Inner JOIN OACT T2 ON T0.[CtlAccount] = T2.[AcctCode]
RIGHT OUTER JOIN OASC T3 ON T2.Segment_1 = T3.Code
WHERE T0.[DocNum] = '161682' OR T0.[DocNum] = '161737' OR T0.[DocNum] = '161738'
AND (T3.SegmentID=1 AND T2.Segment_1 = T3.Code)
I solved this by changing the order in the WHERE statement to:
WHERE
(T3.SegmentID=1 AND T2.Segment_1 = T3.Code)
AND
(T0.[DocNum] = '161682' OR T0.[DocNum] = '161737' OR T0.[DocNum] = '161738')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
the order of the WHERE clause is not changing anything, you will still have the duplicates, but maybe not close to each other.
The best solution would be to use DISTINCT:
SELECT DISTINCT T0.[DocNum], T0.[CtlAccount], T1.[AcctCode], T3.[SegmentId], T3.[Code], T3.[Name]FROM OPCH T0
Regards
Clas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.