Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

query problem

hi there again,

as i asked i write a query for udf´s in business partners like this one :

SELECT T0.[CardCode],T0.[U_altekdnr], T2.[Descr], T3.[Descr], T1.[Country] FROM .[OCRD] T0 INNER JOIN UFD1 T2 ON T2.FldValue = T0.U_gruppe INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode AND T1.Address = 'Standard RE' INNER JOIN UFD1 T3 ON T3.FldValue = T0.U_kundenart WHERE T0.U_gruppe = AND T0.U_kundenart =

The problem is that i get each CardCord entry repeated for each table. e.g. CardCode 1 is twice in OCRD, once in CRD1 and twice in UFD1, the result is 5 lines with CardCode 1.

But i only want one result line. The statement DISTINCT does not help. Any ideas ?


Former Member

I think a Distinct keyword is missing. Try this:

SELECT distinct T0.CardCode,T0.U_altekdnr,
 (Select Top 1 T2.Descr From UFD1 T2 Where T2.FldValue = T0.U_gruppe),
 (Select Top 1 T3.Descr From UFD1 T3 Where T3.FldValue = T0.U_kundenart),
FROM dbo.OCRD T0 INNER JOIN UFD1 T2 ON T2.FldValue = T0.U_gruppe
WHERE T0.U_gruppe = [%1] AND T0.U_kundenart = [%2]

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question