cancel
Showing results for 
Search instead for 
Did you mean: 

For a Product last Business partner to find Query SAP B1

0 Kudos

Hello

How can i find for a product last order(Business partner) in Query? (Query will not give another orders for Product (Only last order))

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

azizelmir
Contributor
0 Kudos

Hi Onurcan,

The attached Query provides results in a manner and form that you have requested.

Select W1.Cardcode,W1.CardName, W1.Docnum, w1.DocTotal, W1.Docdate
From
(SELECT  T0.CardCode, T0.CardName, T0.DocNum, T0.DocTotal, t0.Docdate
,ROW_NUMBER() OVER (PARTITION BY t0.Cardcode  ORDER BY t0.Docnum DESC) AS rn
FROM OPOR T0  
WHERE (select Top 1  ShipDate from POR1 where POR1.Docentry=T0.Docentry)  - CONVERT (date, GETDATE()) BETWEEN -200 AND 0
---Order by t0.Cardname asc , Docnum desc
) 
as W1 where rn=1 
order by  W1.CardCode asc

Thank you,

Aziz

0 Kudos

Thank you for your answer

I can't see my products name or Products Price

How can I see this informations?

azizelmir
Contributor

Here you go ...

Select W1.ItemCode,W1.Dscription,W1.Price ,W1.CardName, W1.Docnum, w1.DocTotal, W1.Docdate as 'Posting Date'
From
(
SELECT  T1.ItemCode,T1.Dscription,T1.Price,T0.CardCode, T0.CardName, T0.DocNum, T0.DocTotal, t0.Docdate
,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  
WHERE (select Top 1  ShipDate from POR1 where POR1.Docentry=T0.Docentry)  - CONVERT (date, GETDATE()) BETWEEN -200 AND 0
) 
as W1 where rn=1 
order by  W1.ItemCode asc

Answers (2)

Answers (2)

former_member294403
Participant
0 Kudos

Try this modified query

SELECT TOP 1 T1.[ShipDate], T1.[ItemCode], T1.[Dscription], T1.[Price], T0.[CardName] FROM OPOR T0  INNER JOIN POR1 T1 ON T0.[DocEntry]= T1.[DocEntry] WHERE T1.[ShipDate]- CONVERT(date, GETDATE()) BETWEEN -200 AND 0 ORDER BY T1.[ShipDate]
0 Kudos

This Query give me only last order for last product. I want to see for all products last business partner.

Thank you

former_member294403
Participant
0 Kudos

Try this

SELECT TOP 1 T0.CardCode, T0.CardName, T0.DocNum, T0.DocDate, T0.DocTotal

FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry =  T1.DocEntry

WHERE T1.ItemCode = [%0]

ORDER BY T0.DocDate DESC, T0.DocNum Desc
0 Kudos

Thank you for your answer

Can you help with my Query?

I want to see only last order(Business Partner) for Products

SELECT T1.[ShipDate], T1.[ItemCode], T1.[Dscription], T1.[Price], T0.[CardName] FROM OPOR T0  INNER JOIN POR1 T1 ON T0.[DocEntry] = T1.[DocEntry] 
WHERE T1.[ShipDate] - CONVERT (date, GETDATE()) BETWEEN -200 AND 0
ORDER BY T1.[ShipDate]