I have a function that takes 2 parameters: @iEmployeeID
and @dDate
.
It's purpose is to find a budget rate for the given parameters. In other words, it should find the largest date being smaller or equal to the @dDate
argument, and return the rate that corresponds.
Budget rates are:
Start Rate ------- ----- 01-01-2008 600 01-01-2009 800 01-01-2010 700
DECLARE @result decimal(38,20)
SELECT @result = decRate
FROM BudgetRates BR
WHERE BR.iRefEmployeeID = @iEmployeeID
GROUP BY decRate
HAVING MAX(BR.dStart) <= @dDate
RETURN @result
- When supplied the argument
06-06-2008
, it correctly returns 600. - When supplied the argument
03-03-2009
, it correctly returns 800 - When supplied the argument
02-02-2010
, it should return 700. The function actually returns 800.
Where is the bug?
bug hunting: If I tweak around with the figures, it seems to pick the largest rate if it has 2 values to pick from.