cancel
Showing results for 
Search instead for 
Did you mean: 

Query total discount applied in sales orders.

0 Kudos

We need to make a query that shows the total discount of the sales orders. The problem is that sales order discounts in our company are made by lines.Contagem de

View Entire Topic
former_member312729
Active Contributor

Hi Cristian,

Try this

SELECT Distinct T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DocTotal], Sum(T1.[DiscPrcnt]) [Total Discount %], Sum(T1.[LineTotal]) [TotalAmount With Disc] , Sum((T1.[Quantity] * T1.[PriceBefDi]))[TotalAmount Without Disc]  ,(Sum((T1.[Quantity] * T1.[PriceBefDi])) - Sum(T1.[LineTotal]))[Total Discount]  FROM ORDR T0  INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry] WHERE T0.[DocDate] >=[%0] AND  T0.[DocDate] <=[%1]
Group By T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], T0.[DocTotal]