Skip to Content

How many sales in 30 Days SAP B1 Query?

Hello

In this query I want to have in 30 days total sales Quantity for Products. I have an Query but don't give correct value

Thank You

Select W1.[ItemCode],W1.[Dscription], W1.[OnHand], W1.[OnOrder], W1.[IsCommited] 'Bestätigt',W1.[Quantity], W1.[Price] ,W1.[CardName], W1.[Docnum], W1.[Docdate] as 'Posting Date'
FROM
(
SELECT  T1.ItemCode,T1.Dscription, T3.OnHand,T3.[OnOrder],T3.[IsCommited], T1.Price,T0.CardCode, T0.CardName, T0.DocNum, T0.Docdate, T3.WhsCode, T4.[Quantity], T5.[Comments]
,ROW_NUMBER() OVER (PARTITION BY t1.ItemCode ORDER BY t0.Docnum DESC) AS rn
FROM OPOR T0 
INNER JOIN POR1 T1 ON T0.Docentry=T1.Docentry
INNER JOIN OITM T2 ON T1.ItemCode= T2.ItemCode
INNER JOIN OITW T3 ON T2.[ItemCode] = T3.[ItemCode]
INNER JOIN INV1 T4 ON T2.[ItemCode] = T4.[ItemCode]
INNER JOIN OINV T5 ON T4.[DocEntry] = T5.[DocEntry]
WHERE 
(SELECT TOP 1 ShipDate FROM POR1 where POR1.DOCENTRY=T0.DOCENTRY)  - CONVERT (date, GETDATE()) BETWEEN -200 AND 0) 
as W1 WHERE rn=1 AND W1.WhsCode = '01'
ORDER BY  W1.ItemCode asc

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Feb 24, 2019 at 04:41 AM

    Dear Onurcan,

    OPOR and POR1 Table is for Purchase order document. Please change this table to ORDR and RDR1 and check.

    If you need Sales invoice detail change it to OINV and INV1.

    Select W1.[ItemCode],W1.[Dscription], W1.[OnHand], W1.[OnOrder], W1.[IsCommited]'Bestätigt',W1.[Quantity], W1.[Price],W1.[CardName], W1.[Docnum], W1.[Docdate]as'Posting Date'FROM(SELECT  T1.ItemCode,T1.Dscription, T3.OnHand,T3.[OnOrder],T3.[IsCommited], T1.Price,T0.CardCode, T0.CardName, T0.DocNum, T0.Docdate, T3.WhsCode, T4.[Quantity], T5.[Comments],ROW_NUMBER() OVER (PARTITION BY t1.ItemCode ORDERBY t0.Docnum DESC)AS rn
    FROM ORDR T0 
    INNERJOIN RDR1 T1 ON T0.Docentry=T1.Docentry
    INNERJOIN OITM T2 ON T1.ItemCode= T2.ItemCode
    INNERJOIN OITW T3 ON T2.[ItemCode]= T3.[ItemCode]INNERJOIN INV1 T4 ON T2.[ItemCode]= T4.[ItemCode]INNERJOIN OINV T5 ON T4.[DocEntry]= T5.[DocEntry]WHERE(SELECTTOP1 ShipDate FROM RDR1 where RDR1.DOCENTRY=T0.DOCENTRY)-CONVERT(date, GETDATE())BETWEEN-200AND0)as W1 
    
    WHERE rn=1AND W1.WhsCode ='01' AND W1.[Docdate] ≥ [%0] and W1.[Docdate] ≤ [%1]
    
    ORDERBY  W1.ItemCode asc
    
    
    Mention from date and to date

    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.