Hello,
Is it possible to group all of the results in this query by BP Code? I have applied the Group BY but it is still showing each line for each BP, rather a total cumulative value for each BP. ANy ideas on how to get one result for each BP?
Thanks and appreciate the insight!
Here is the query I am using:
select T1.cardcode 'Bp Code',T1.cardname 'Name',T1.Address, T1.ZipCode, T1.Phone1, T1.e_mail, getdate() AS 'Report Date', sysdeb 'Debit Amount',syscred 'Credit Amount', (sysdeb - syscred) as 'Balance Due',
case T0.transtype
when '13' then 'INV'
when '14' then 'AR CN'
when '24' then 'INCOMING'
else 'Other'
end 'Type',
Ref1,
fccurrency 'BP Currency',
CONVERT(VARCHAR(10), refdate, 103) 'Posting Date',
CONVERT(VARCHAR(10), duedate, 103) 'Due Date',
CONVERT(VARCHAR(10), taxdate, 103) 'Doc Date' ,
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 < 31
then
case
when syscred <> 0 then -syscred
else sysdeb
end
end "0-30 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 30
and (datediff(dd,refdate,current_timestamp))+1< 61)
then
case
when syscred <> 0 then -syscred
else sysdeb
end
end "31 to 60 days",
case when ((datediff(dd,refdate,current_timestamp))+1 > 60
and (datediff(dd,refdate,current_timestamp))+1< 91)
then
case
when syscred <> 0 then -syscred
else sysdeb
end
end "61 to 90 days",
CASE
when (DATEDIFF(dd,refdate,current_timestamp))+1 > 90
then
case
when syscred= 0 then sysdeb
when sysdeb= 0 then -syscred
end
end "90 + days"
from dbo.JDT1 T0
INNER JOIN dbo.OCRD T1 ON T0.shortname = T1.cardcode and T1.cardtype = 'c'
where T0.intrnmatch = '0' and T0.BALDUEDEB != T0.BALDUECRED AND T1.GroupCode = '103'
group by
T1.cardcode,T1.cardname,T1.Address, T1.ZipCode, T1.Phone1, T1.e_mail, T0.sysdeb, T0.syscred, T0.transtype, T0.Ref1, T0.FCCurrency, T0.Refdate, T0.duedate, T0.taxdate
ORDER BY T1.Cardcode, T0.taxdate