cancel
Showing results for 
Search instead for 
Did you mean: 

Query Aging Report 50 days past due

former_member587037
Discoverer
0 Kudos

Hi Everyone,

The query below returns two lines per business partner, one line for the OINV total and one line for the ORIN total (like table one below).


I would like the query to instead return one line per business partner, summing the OINV and ORIN totals (like table two below).

Does anyone know how to do this?

Thanks!

Jeff

TABLE ONE

P CodeBP NameAmount 50 Days Past Due
10000Test BP17,000.00
10000
Test BP
-2,000.00

TABLE TWO

BP CodeBP NameAmount 50 Days Past Due
10000Test BP15,000.00

Query:

/*AR Invoice 50 Days Past Due 2.0*/

SELECT distinct T0.CardCode, T0.[CardName], sum(T0.[DocTotal]-T0.PaidToDate) AS 'Amount 50 Days Past Due' FROM OINV T0 WHERE datediff (day,T0.DocDate,getdate()) >50 Group By T0.CardCode, T0.CardName

UNION

SELECT distinct ORIN.CardCode, ORIN.[CardName], sum((ORIN.[DocTotal]-ORIN.PaidToDate)*-1) AS 'Amount 50 Days Past Due' FROM ORIN ORIN WHERE datediff (day,ORIN.DocDate,getdate()) >50 Group By ORIN.CardCode, ORIN.CardName

Accepted Solutions (1)

Accepted Solutions (1)

KennedyT21
Active Contributor
0 Kudos

Hi Jeff,

Try this


Select TT.CardCode,TT.CardName,sUM(TT.INV+TT.CN) aS 'Amount 50 Days Past Due'   FROM  (

SELECT distinct T0.CardCode, T0.[CardName], sum(T0.[DocTotal]-T0.PaidToDate) AS 'INV',0 AS 'CN' FROM OINV T0 WHERE datediff (day,T0.DocDate,getdate()) >50 Group By T0.CardCode, T0.CardName

UNION

SELECT distinct ORIN.CardCode, ORIN.[CardName],0, sum((ORIN.[DocTotal]-ORIN.PaidToDate)*-1) AS 'CN' FROM ORIN ORIN WHERE datediff (day,ORIN.DocDate,getdate()) >50 Group By ORIN.CardCode, ORIN.CardName ) as TT

GROUP BY TT.CardCode,TT.CardName

Cheers

Kennedy

former_member587037
Discoverer
0 Kudos

Thank you Kennedy, this works perfectly!

KennedyT21
Active Contributor
0 Kudos

can i get ur mail id

Former Member
0 Kudos

Dear Sir,

In the above query can you please few changes if possible

1.we want exclude few customers(our inter branch)we use for internal stock transfer.

2.Sales Person and if possible please add golden arrow

KennedyT21
Active Contributor
0 Kudos

As per forum rules open a new thread to get experts answers . dont post on the close thread

Answers (0)