What am I missing here?
select cast ( ( cast (100 * 39 as decimal ) / 41) as decimal(5,2))
gives a result of 95.12
but
declare @percent decimal
set @percent = cast ( ( cast (100 * 39 as decimal ) / 41) as decimal(5,2))
select @percent
gives a result of 95
What happened to the two 2 decimal points and how do I get them back into my variable?
DECIMALon its own does not have any decimal places (it’s actuallyDECIMAL(18,0)). You need to specify precision and scale, e.g.