February 17, 2009 at 5:40 am
The function needs to be schemabound
CREATE FUNCTION
[dbo].[Calculation] ( @p1 INT, @p2 TINYINT, @p3 TINYINT)
RETURNS INT
WITH SCHEMABINDING
AS
BEGIN
DECLARE @ReturnVal INT
SET @ReturnVal = @p1 + @p1*@p2/100 - @p1*@p3/100
RETURN @Returnval
END
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
February 17, 2009 at 6:22 am
Schemabinding guarantees that the dependancies of the function (e.g. column types) cannot be changed without first altering the function. Check BOL for more information.
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
February 18, 2009 at 7:45 am
You should be careful with this function, as it will produce zero in situations where you otherwise would expect a non-zero result. Since none of your calculations are parameterized, you will default to the SQL Server rules regarding precision. For example, if your values for @p1, @p2, adn @p3 are 1,1,and 199, the result will be zero. There are many other conditions under which this will be true.
Viewing 4 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply