销售查询中的物料属性

时间:2017-12-28 18:31:41

标签: sapb1

我有一个销售查询,我需要从OITG表添加项目组属性。但找不到任何直接链接。我是新手所以真的不知道如何在下面的查询中添加Item组属性。请指教。

Select T0.[DocNum], 
       T0.[DocDate], 
       Case when T0.[ObjType] = 13 then 'INVOICE' when T0.[ObjType] = 14 then 'CREDIT NOTE' end as 'Type',
    T0.[CardCode], 
    T0.[CardName], 
    T1.[ItemCode], 
    T1.[Dscription],
    T1.[Quantity], 
    T0.[DocCur], 
    T1.[LineTotal] as 'Canadian, 
    Case when T1.[Rate] = 0 then T1.[LineTotal] else (T1.[LineTotal]/T1.[Rate]) end as 'Equivalent Value',
    Case when (T1.[Quantity] = 0 and (T1.[StockPrice]*T1.[Quantity])= 0 )  then T1.[LineTotal] else (T1.[INMPrice]*T1.[Quantity]) end as 'Sales - Net',
    (T1.[StockPrice]*T1.[Quantity]) as 'Cost',
    T1.[GrssProfit],
    Case when (T1.[INMPrice]*T1.[Quantity]) =0 then 0 else (T1.[GrssProfit]/(T1.[INMPrice]*T1.[Quantity]))*100 end as 'GP %age'
    FROM 
    OINV T0  INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
    WHERE 
    T0.[CANCELED] = 'N' and
    T0.[DocDate]   >= [%0] and
    T0.[DocDate] <=[%1] and
    T1.[LineTotal] <> '0'

and i want to add a below subquery to above query.

    src.ItemCode,src.ItemName,src.ItmsGrpNam

    from

    (select OITM.ItemCode,OITM.ItemName,OITG.ItmsGrpNam

    from OITM CROSS JOIN OITG

    where OITM.QryGroup1 = 'Y' and OITG.ItmsTypCod = 1

1 个答案:

答案 0 :(得分:0)

Select T0.[DocNum], 
T0.[DocDate], 
Case when T0.[ObjType] = 13 then 'INVOICE' when T0.[ObjType] = 14 then 'CREDIT NOTE' end as 'Type',
T0.[CardCode], 
T0.[CardName], 
T1.[ItemCode], 
T1.[Dscription],
T1.[Quantity], 
T0.[DocCur], 
T1.[LineTotal] as 'Canadian', 
Case when T1.[Rate] = 0 then T1.[LineTotal] else (T1.[LineTotal]/T1.[Rate]) end as 'Equivalent Value',
Case when (T1.[Quantity] = 0 and (T1.[StockPrice]*T1.[Quantity])= 0 )  then T1.[LineTotal] else (T1.[INMPrice]*T1.[Quantity]) end as 'Sales - Net',
(T1.[StockPrice]*T1.[Quantity]) as 'Cost',
T1.[GrssProfit],
Case when (T1.[INMPrice]*T1.[Quantity]) =0 then 0 else (T1.[GrssProfit]/(T1.[INMPrice]*T1.[Quantity]))*100 end as 'GP %age'
, T3.ItmsGrpNam
FROM OINV T0 
INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
LEFT JOIN OITG T3 ON CASE WHEN ISNULL(T2.QryGroup1, '') = 'Y' THEN 1 WHEN ISNULL(T2.QryGroup2, '') = 'Y' THEN 2 END  = ItmsTypCod
WHERE 
T0.[CANCELED] = 'N' and
T0.[DocDate]   >= [%0] and
T0.[DocDate] <=[%1] and
T1.[LineTotal] <> '0'