Skip to main content
1 de 3

How to assign numbers into my @declare variable

I'm trying to get a percentage value in SQL Server, but I'm not sure of what are the declarations I must use to get my value, accurate not need to be more than 5 values.

Here's the code I'm using

DECLARE @Mx_Fy AS INT = (SELECT MAX(Year) FROM My_Table) 
DECLARE @FyM1 AS INT =  (SELECT COUNT(DISTINCT(Request)) 
                        FROM My_Table WHERE Year = @Mx_Fy-1)
DECLARE @FyM2 AS INT =  (SELECT COUNT(DISTINCT(Request)) 
                        FROM My_Table WHERE Year = @Mx_Fy-2)

--SELECT @FyM1 --> 689
--SELECT @FyM2 --> 472

DECLARE @FcstPct AS FLOAT(5) = @FyM1/@FyM2 

SELECT  @FcstPct --> 1 >:(

Unfortunately I'm not getting the value I need, that must be 1.45974

I got this

For sure that is not 1!!

Can somebody help me?