I am trying to do a sum on amount (t_amnt) but I need to know whether it is a debit or credit first. it is stored as a binary field, however I was able to get the value of debit = 0x01 and credit = 0x02.
Anyone know how I can write this to process correctly?
sum(
case
when t_dbcr = '0x01' then t_amnt
when t_dbcr = '0x02' then -t_amnt
end)
Much appreciation
Oh, here is the whole query:
SELECT t_leac, sum(
case
when t_dbcr = '0x01' then t_amnt
when t_dbcr = '0x02' then -t_amnt
end),
t_fyer, t_fprd
from [baandb].[dbo].[ttfgld410100]
where t_fyer >= 2005 and t_fprd = 1 and t_dbcr = 0x01
group by t_leac, t_fyer, t_fprd
order by t_fyer, t_fprd, t_leac
Anyone know how I can write this to process correctly?
sum(
case
when t_dbcr = '0x01' then t_amnt
when t_dbcr = '0x02' then -t_amnt
end)
Much appreciation
Oh, here is the whole query:
SELECT t_leac, sum(
case
when t_dbcr = '0x01' then t_amnt
when t_dbcr = '0x02' then -t_amnt
end),
t_fyer, t_fprd
from [baandb].[dbo].[ttfgld410100]
where t_fyer >= 2005 and t_fprd = 1 and t_dbcr = 0x01
group by t_leac, t_fyer, t_fprd
order by t_fyer, t_fprd, t_leac