# 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
```
10|10000 characters needed characters exceeded

### Related questions

• 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