my table stored with
TABLE [dbo].[table_A](
ID nvarchar not null,
[expected_amouunt] nvarchar NULL,
[actual_amount] nvarchar NULL,
) ON [PRIMARY]
GO
ID expected_amouunt actual_amount
1 0 17.5
i would like to extract from table_A with the following output
ID DR CR
1 (display blank) 17.5
DR column:(when actual_amount - expected_amouunt)<0 then display (when actual_amount - expected_amouunt) else ''
CR column : (when actual_amount - expected_amouunt)>0 then display (when actual_amount - expected_amouunt) else ''
select ID,
case when
cast (cast (([actual_amount],'0') as float) as money) - cast (cast ([expected_amouunt] as float) as money) < 0 then
cast (cast ([actual_amount] as float) as money) - cast (cast ([expected_amouunt] as float) as money) else '' end as [DR],
case when
cast (cast (([actual_amount],'0') as float) as money) - cast (cast ([expected_amouunt] as float) as money) > 0 then
cast (cast ([actual_amount] as float) as money) - cast (cast ([expected_amouunt] as float) as money) else '' end as [CR]
from table_A;
i don't know why it is always return 0.00 for "DR" even the (when actual_amount - expected_amouunt) > 0, if it greater then zero, it should fall into "Else" , so it should display blank ''.
how to fix it?