David..
Try This
Select T1.RefDate,
Case
When T1.TransType=13 Then 'Invoice'
When T1.TransType=14 Then 'A/R Credit Memo'
When T1.TransType=15 Then 'Delivery Note'
When T1.TransType=16 Then 'Delivery Return'
When T1.TransType=162 Then 'Stock Revaluation'
When T1.TransType=18 Then 'Purchase Bill'
When T1.TransType=19 Then 'A/P Credit Memo'
When T1.TransType=20 Then 'GRPO'
When T1.TransType=202 Then 'Work Order'
When T1.TransType=21 Then 'Goods Return'
When T1.TransType=24 Then 'Incoming Payment'
When T1.TransType=30 Then 'Journal'
When T1.TransType=46 Then 'Outgoing Payment'
When T1.TransType=59 Then 'Goods Receipt'
When T1.TransType=60 Then 'Goods Issue'
When T1.TransType=67 Then 'Stock Transfer'
Else T1.TransType
End [TransType],
T1.TransId,
Case
-- Sales A/R
When T1.TransType = 13 Then (Select isnull(Comments, '') From OINV Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Invoice
When T1.TransType = 14 Then (Select isnull(Comments, '') From ORIN Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- A/R Credit Memo
When T1.TransType = 15 Then (Select isnull(Comments, '') From ODLN Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Delivery
When T1.TransType = 16 Then (Select isnull(Comments, '') From ORDN Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Delivery Return
-- Purchase A/P
When T1.TransType = 18 Then (Select isnull(Comments, '') From OPCH Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Purchase Bill
When T1.TransType = 19 Then (Select isnull(Comments, '') From ORPC Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- A/P Credit Memo
When T1.TransType = 20 Then (Select isnull(Comments, '') From OPDN Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- GRPO
When T1.TransType = 21 Then (Select isnull(Comments, '') From ORPD Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Goods Return
-- Production
When T1.TransType = 202 Then (Select isnull(Comments,'') From OWOR Where DocNum = T1.BaseRef and PostDate = T1.RefDate) -- Work Order
-- Banking
When T1.TransType = 24 Then (Select isnull(Comments, '') From ORCT Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Incoming Payment
When T1.TransType = 46 Then (Select isnull(Comments, '') From OVPM Where DocNum = T1.BaseRef and CardCode = T1.ShortName) -- Outgoing Payment
When T1.TransType = 30 Then (Select ISNULL(LineMemo, '') From JDT1 Where Ref1 = T1.Ref1 and ShortName = T1.ShortName) -- Journal
-- Inventory
When T1.TransType = 59 Then (Select ISNULL(Comments, '') From OIGE Where DocNum = T1.Ref1 and DocDate = T1.RefDate) -- Goods Receipt
When T1.TransType = 60 Then (Select ISNULL(Comments, '') From OIGN Where DocNum = T1.Ref1 and DocDate = T1.RefDate) -- Goods Issue
When T1.TransType = 67 Then (Select ISNULL(Comments, '') From OWTR Where DocNum = T1.Ref1 and DocDate = T1.RefDate) -- Stock Transfer
When T1.TransType = 162 Then (Select ISNULL(Comments, '') From OMRV Where DocNum = T1.Ref1 and DocDate = T1.RefDate) -- Stock Revaluation
Else ''
End [Remarks],
T1.LineMemo,
Case
When exists (Select AcctCode From OACT Where AcctCode = T1.ContraAct)
Then (Select AcctName From OACT Where AcctCode = T1.ContraAct)
else (Select CardName From OCRD Where CardCode = T1.ContraAct)
End [Account],
Case
When T1.Debit=0.0
Then 0.0
Else T1.Debit
End Debit,
Case
When T1.Credit=0.0
Then 0.0
Else T1.Credit
End Credit
From JDT1 T1
Where T1.TransType <> -3
And T1.RefDate Between @FromDate and @ToDate
And T1.ShortName = @Account
Order By T1.RefDate,
T1.TransId
Regards
Kennedy