I want to calculate the percentage change of some statistics id using SQLSEVER.
I want to calculate %change using = ((curr-prev)/prev) * 100
My %change expected there was 2.63% since (400008/15189461)* 100 but I am getting result as 0.00%.
select
c.poscount as curr,
p.poscount as 'prev',
(p.PosCount - c.PosCount) 'difference',
CONVERT(
decimal(2, 2),
(p.PosCount - c.PosCount)/ NULLIF(p.PosCount, 0)
) as 'Poscountchange'
from
(
select
*
from
Goker.dbo.LocalStatisticsDetail_daily
where
statisticid = '13527'
) c
inner join (
select
*
from
Goker.dbo.LocalStatisticsDetail_daily
where
statisticid = '13373'
) p on c.fieldname = p.fieldname
Why I am getting 0% as percentage change? I didn't wanted to change to decimal at first and my result was 0% before converting it into decimal.