I have this strange problem where a Calculation in my Stored Procedure only shows the Int Value. The Code below always returns 0 or 1 and never the decimal value. Can some on help?
DECLARE @HAMS int,
@SPAMS int,
@GOOD int,
@BAD int,
@SCORE decimal(14,3)
SET @HAMS = (SELECT dbo.Params.BayeHam FROM dbo.Params WHERE Config = 0)
SET @SPAMS = (SELECT dbo.Params.BayeSpam FROM dbo.Params WHERE Config = 0)
SET @GOOD = (SELECT dbo.Tokens.Hams FROM dbo.Tokens WHERE Token =@TOKEN)
SET @BAD = (SELECT dbo.Tokens.Spams FROM dbo.Tokens WHERE Token =@TOKEN)
IF @HAMS < 0 SET @HAMS = 0
IF @SPAMS < 0 SET @SPAMS = 0
IF @SPAMS = 0 OR @HAMS = 0
BEGIN
IF @HAMS > 0 SET @SCORE = 0
IF @SPAMS > 0 SET @SCORE = 1
END
ELSE
BEGIN
SET @SCORE =CONVERT(DECIMAL(14,2), (@BAD / @SPAMS) / ((@GOOD / @HAMS) + (@BAD / @SPAMS)))
IF @SCORE > 1 SET @SCORE = 1
IF @SCORE < 0 SET @SCORE = 0
END
--SET @SCORE = 0.99
UPDATE dbo.Tokens
SET dbo.Tokens.Score = (@SCORE)
WHERE dbo.Tokens.Token = @TOKEN
DECLARE @HAMS int,
@SPAMS int,
@GOOD int,
@BAD int,
@SCORE decimal(14,3)
SET @HAMS = (SELECT dbo.Params.BayeHam FROM dbo.Params WHERE Config = 0)
SET @SPAMS = (SELECT dbo.Params.BayeSpam FROM dbo.Params WHERE Config = 0)
SET @GOOD = (SELECT dbo.Tokens.Hams FROM dbo.Tokens WHERE Token =@TOKEN)
SET @BAD = (SELECT dbo.Tokens.Spams FROM dbo.Tokens WHERE Token =@TOKEN)
IF @HAMS < 0 SET @HAMS = 0
IF @SPAMS < 0 SET @SPAMS = 0
IF @SPAMS = 0 OR @HAMS = 0
BEGIN
IF @HAMS > 0 SET @SCORE = 0
IF @SPAMS > 0 SET @SCORE = 1
END
ELSE
BEGIN
SET @SCORE =CONVERT(DECIMAL(14,2), (@BAD / @SPAMS) / ((@GOOD / @HAMS) + (@BAD / @SPAMS)))
IF @SCORE > 1 SET @SCORE = 1
IF @SCORE < 0 SET @SCORE = 0
END
--SET @SCORE = 0.99
UPDATE dbo.Tokens
SET dbo.Tokens.Score = (@SCORE)
WHERE dbo.Tokens.Token = @TOKEN