我正在尝试为每位客户提供净价的价目表,但是根据customerdiscountgroup,它返回不同数量的行号。 我想我知道问题从哪里开始,但我不知道如何解决。
有325个商品组和3个客户折扣组。 在第一个客户折扣组中,每个项目组都有一个折扣,因此查询返回数据库中存在的每个项目。
在第二个和第三个客户折扣组中,+ /-300个项目组有折扣,其他25个项目组没有折扣。项目组在客户折扣组下的SAP B1中列出,但默认折扣为0,00。 这些带有0,00的元素未在EDG1表中列出,因此这些项目组下的项目不会返回我的结果中。
那么我如何获得没有折扣的商品以返回我的结果?
SELECT T4."ItemCode"
, T4."SuppCatNum" AS "FabrikantCode"
, T4."QryGroup4" AS "EOL"
, T4."QryGroup1" AS "Stock"
, T4."QryGroup2" AS "Bestelartikel"
, T4."U_CG_WSHoofdgroep" AS "Hoofdgroep"
, T4."U_CG_WSSub1" AS "Subgroep"
, T4."U_CG_WSSub1Filter1" AS "Merk"
, T4."ItemName" AS "Artikelomschrijving"
, T4."SalUnitMsr" AS "Eenheid"
, T3."ItmsGrpNam" AS "ArtikelGroep"
, T5."Price" AS "Bruto"
, T2."Discount" AS "StandaardKorting"
, Extra."Extra" AS "ExtraK"
, Artikel."ArtikelKorting" AS "ArtK"
, CASE WHEN T2."Discount" IS NULL AND Extra."Extra" IS NULL AND Artikel."ArtikelKorting" IS NULL THEN T5."Price"
WHEN T2."Discount" IS NOT NULL AND Extra."Extra" IS NULL AND Artikel."ArtikelKorting" IS NULL THEN (T5."Price" * ((100-T2."Discount")/100))
WHEN T2."Discount" IS NOT NULL AND Extra."Extra" IS NOT NULL AND Artikel."ArtikelKorting" IS NULL THEN (T5."Price" * ((100-T2."Discount")/100) * ((100-Extra."Extra")/100))
WHEN T2."Discount" IS NOT NULL AND Extra."Extra" IS NOT NULL AND Artikel."ArtikelKorting" IS NOT NULL THEN (T5."Price" * ((100-T2."Discount")/100) * ((100-Extra."Extra")/100) * ((100-Artikel."ArtikelKorting")/100))
WHEN T2."Discount" IS NOT NULL AND Extra."Extra" IS NULL AND Artikel."ArtikelKorting" IS NOT NULL THEN (T5."Price" * ((100-T2."Discount")/100) * ((100-Artikel."ArtikelKorting")/100)) END AS "Netto"
FROM OCRD T0
LEFT JOIN OEDG T1 ON T0."GroupCode" = T1."ObjCode" AND (T1."ObjCode"='104' OR T1."ObjCode"='106')
LEFT JOIN EDG1 T2 ON T1."AbsEntry" = T2."AbsEntry" AND T2."ObjType"='52'
LEFT JOIN OITB T3 ON T2."ObjKey"=T3."ItmsGrpCod"
LEFT JOIN (SELECT
T1."CardCode" AS "KlantCode", T3."ItmsGrpNam" AS "ArtikelGroep", T2."Discount" AS "Extra"
FROM OEDG T0
LEFT JOIN OCRD T1 ON T0."ObjCode"=T1."CardCode"
LEFT JOIN EDG1 T2 ON T0."AbsEntry" = T2."AbsEntry" AND T2."ObjType"='52'
LEFT JOIN OITB T3 ON T2."ObjKey"=T3."ItmsGrpCod"
) Extra ON T0."CardCode"=Extra."KlantCode" AND T3."ItmsGrpNam"=Extra."ArtikelGroep"
RIGHT JOIN OITM T4 ON T3."ItmsGrpCod" = T4."ItmsGrpCod"
LEFT JOIN ITM1 T5 ON T4."ItemCode"=T5."ItemCode" AND T5."PriceList"='2'
LEFT JOIN (SELECT T3."CardCode" AS "KlantCode", T0."ItemCode" AS "ArtikelCode", T0."ItemName", T0."ItmsGrpCod", T2."ObjType", T2."ObjKey", T2."Discount" AS "ArtikelKorting", T1."Type", T1."ObjType", T1."ObjCode"
FROM OITM T0
LEFT JOIN EDG1 T2 ON T0."ItemCode" = T2."ObjKey"
LEFT JOIN OEDG T1 ON T2."AbsEntry"=T1."AbsEntry"
RIGHT JOIN OCRD T3 ON T1."ObjCode" = T3."CardCode"
WHERE T2."ObjType"='4') Artikel ON T0."CardCode"=Artikel."KlantCode" AND T5."ItemCode" = Artikel."ArtikelCode"
WHERE T0."CardCode"='[%CardCode]'