cancel
Showing results for 
Search instead for 
Did you mean: 

i need to remove duplicates in this query anyone help me??????

JAYAKUMAR2
Explorer
0 Kudos

SELECT DISTINCT T2."DocEntry",
T2."DocNum" AS "RR NO",T2."CardName" AS "Name of the Supplier/Manufacturer",
T3."ItemCode" AS "Itemcode",
T3."Dscription" AS "Item Description",T4."InvntryUom" AS "UOM",
T15."U_UTL_BTNO" AS "Mfg Batchno",
T15."U_UTL_MFDT",
T15."U_UTL_EXDT",
T15."U_UTL_ANDT",
T15."U_UTL_RTDT",
T15."U_UTL_ARNO", T15."U_UTL_APPQ",T15."U_UTL_REJQ",

T3."PriceBefDi" AS "Rate",
T3."PriceBefDi" * T15."U_UTL_APPQ"-T15."U_UTL_REJQ" AS "Value",T103."Quantity",

Case when (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode") >0
then (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode")-T103."Quantity"
ELSE (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode")+T15."U_UTL_APPQ"
end as "Balance qty"


FROM OPDN T2 INNER JOIN PDN1 T3 ON T2."DocEntry" = T3."DocEntry"
LEFT OUTER JOIN OITM T4 ON T4."ItemCode" = T3."ItemCode"
LEFT OUTER JOIN ITM1 T5 ON T5."ItemCode" = T4."ItemCode"
LEFT OUTER JOIN OITB T6 ON T6."ItmsGrpCod" = T4."ItmsGrpCod"
LEFT OUTER JOIN "@UTL_OQCHK" T15 ON T15."U_UTL_GRDE"=T3."DocEntry" AND T15."U_UTL_OBTP"=t3."ObjType"
LEFT OUTER JOIN IBT1 ON IBT1."BaseEntry" = t3."DocEntry" AND IBT1."ItemCode" = t3."ItemCode" AND IBT1."WhsCode" = t3."WhsCode" AND IBT1."BaseLinNum" = t3."LineNum" AND IBT1."BaseType" = t3."ObjType"
LEFT OUTER JOIN OBTN ON IBT1."BatchNum" = OBTN."DistNumber" AND IBT1."ItemCode" = OBTN."ItemCode"
LEFT OUTER JOIN IGN1 T103 ON T103."ItemCode"= T3."ItemCode"
LEFT OUTER JOIN OIGN T104 ON T104."DocEntry"= T103."DocEntry"

WHERE T2."DocDate" >= [%0] AND T2."DocDate" <=[%1] AND T6."ItmsGrpNam"=[%2]

 

 

JAYAKUMAR2_0-1711709778171.png

 

Sandra_Rossi
Active Contributor
0 Kudos

Please do not post a question about SAP Web sites (community, etc.) if it's not a question about SAP Web sites! You can use Technology Q&A or any groups.

EDIT: now it's fine, the question has been moved under the group Enterprise Resource Planning.

Sandra_Rossi
Active Contributor
0 Kudos

By using DISTINCT, there will be only one line per same values of these below 18 columns, i.e. they CANNOT BE duplicate, so please clarify.

 

SELECT DISTINCT 
T2."DocEntry",
T2."DocNum" AS "RR NO",
T2."CardName" AS "Name of the Supplier/Manufacturer",
T3."ItemCode" AS "Itemcode",
T3."Dscription" AS "Item Description",
T4."InvntryUom" AS "UOM",
T15."U_UTL_BTNO" AS "Mfg Batchno",
T15."U_UTL_MFDT",
T15."U_UTL_EXDT",
T15."U_UTL_ANDT",
T15."U_UTL_RTDT",
T15."U_UTL_ARNO", 
T15."U_UTL_APPQ",
T15."U_UTL_REJQ",
T3."PriceBefDi" AS "Rate",
T3."PriceBefDi" * T15."U_UTL_APPQ"-T15."U_UTL_REJQ" AS "Value",
T103."Quantity",

Case when (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode") >0
then (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode")-T103."Quantity"
ELSE (SELECT sum(a."InQty"-a."OutQty") FROM OINM a WHERE a."DocDate"<[%0] and a."Warehouse" Like '%%APR%%' and a."ItemCode" =T3."ItemCode")+T15."U_UTL_APPQ"
end as "Balance qty"

 

Accepted Solutions (0)

Answers (1)

Answers (1)

JAYAKUMAR2
Explorer
0 Kudos

THIS IS SAP B1 QUESTION ONLY

Sandra_Rossi
Active Contributor
0 Kudos
Please do not post a solution. Instead, click on "show replies" then "comment".