Hi Experts ,
Using this following query:
use MRS2
select por1.LineNum+1"po line#", s.ItemCode, por1.Quantity"PO qty", s.DocEntry, s.[GRPO Qty], s.RunningTotal"GRPO balance", s.GRTqty"GoodReturn", s.[Total Return per GRPO],
CASE when (isnull(s.GRTqty,0) = isnull(s.[Total Return per GRPO],0)) and (isnull(s.GRTqty,0) <> 0 or isnull(s.[Total Return per GRPO],0) <> 0)
then ISNULL(por1.quantity,0) - isnull(s.GRTqty,0)-isnull(s.[GRPO Qty],0)
when isnull(s.GRTqty,0) <> isnull(s.[Total Return per GRPO],0) and (isnull(s.GRTqty,0) <> 0 or isnull(s.[Total Return per GRPO],0) <> 0)
then ISNULL(por1.quantity,0) - isnull(s.[Total Return per GRPO],0)-isnull(s.[GRPO Qty],0)
end as 'GRPO balance qty'
from por1 inner join
(
SELECT distinct a.BaseLine, A.DocEntry, a.BaseEntry, A.ItemCode, A.U_SOL_RETURN, A.Quantity"GRPO Qty", SUM(isnull(B.Quantity,0)) AS RunningTotal , rpd.Quantity"GRTqty",
rpd.DocEntry"GRTdocentry",
rpd.ReturnRunningTotalQty"Total Return per GRPO", w.u_sol_return_option"opsi return",
CASE when ISNULL(rpd.Quantity,0) <> 0
then SUM(isnull(a.Quantity,0)) end as 'Total Quantity'
FROM pdn1 A INNER JOIN pdn1 B
ON A.DocEntry >= B.DocEntry
AND A.itemcode = B.itemcode and a.BaseEntry = b.BaseEntry and a.BaseLine = b.BaseLine
inner join OPDN w on w.DocEntry = a.docentry
left join
(
select T0.docentry,T0.Quantity, t0.BaseEntry
,(select sum(T1.Quantity) from rpd1 T1
where T1.docentry >= T0.docentry and t1.ItemCode = t0.itemcode and t0.u_poline = t1.u_poline) as ReturnRunningTotalQty
from rpd1 T0
) RPD on
rpd.BaseEntry = a.docentry
GROUP BY A.DocEntry, A.ItemCode, A.U_SOL_RETURN, A.Quantity, a.BaseEntry, rpd.Quantity, a.LineNum, a.BaseLine, rpd.DocEntry,
rpd.ReturnRunningTotalQty, w.u_return_option
) s
on s.BaseEntry = por1.DocEntry and s.BaseLine = por1.LineNum
where s.BaseEntry = '73'
and (s.U_RETURN is null or s.U_RETURN = 'rjct') and s.[option return] is null
order by [po line#], s.[Total Return per GRPO] asc
I want to have this result as seen in the following screen shot:
In row #2, the GRPO balance qty column is not correct. GRPO balance qty must be 200. The other rows seems correct.
In row #3, 4, 5 and 6, the GRPO balance column are not correct too. it should be 1000 in the row #5 & 6, and 2000 in the row #4.
Please help to solve this issue. Thank you
Steve