Hi Danielle Napoli
The below query shows the balance due from the customer age date wise only...
Declare @d datetime
set @d
/*Select 1 from jdt1 t where t.duedate*/=[%1]
select * from
(
SELECT T1.CardCode, T1.CardName, T0.RefDate, T0.Ref1 'Document Number',
CASE WHEN T0.TransType=13 THEN 'Invoice'
WHEN T0.TransType=14 THEN 'Credit Note'
WHEN T0.TransType=30 THEN 'Journal'
WHEN T0.TransType=24 THEN 'Receipt'
END AS 'Document Type',
T0.DueDate, (T0.Debit- T0.Credit) 'Balance'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)<=-1),0) 'Future'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)>=0 and DateDiff(day, T0.DueDate,@d)<=30),0) 'Current'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)>30 and DateDiff(day, T0.DueDate,@d)<=60),0) '31-60 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)>60 and DateDiff(day, T0.DueDate,@d)<=90),0) '61-90 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)>90 and DateDiff(day, T0.DueDate,@d)<=120),0) '91-120 Days'
,ISNULL((SELECT T0.Debit-T0.Credit WHERE DateDiff(day, T0.DueDate,@d)>=121),0) '121+ Days'
FROM JDT1 T0 INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
WHERE T1.CardType = 'C'
) sub
Try this for open invoice only
SELECT
T0.[CardCode],
T0.[CardName],
T0.[DocNum],
T0.[DocStatus],
T0.[DocDate],
T0.[DocDueDate],
T0.[DocTotal],
T0.PaidToDate,
(T0.DocTotal - T0.PaidToDate) AS 'Remaining Balance',
DATEDIFF(DAY, T0.DocDueDate, GETDATE( )) AS 'Days Past Due'
FROM dbo.OINV T0
WHERE
T0.[DocStatus] = 'O'
Regards
Kennedy