I have created a simple user-defined function as a test in SQL Server Management Studio 2008. It calculates a person's age based on their date of birth and a second date, at which we want the person's age. The function reads:
CREATE FUNCTION [*myprofile*].[udf_getAge]
(@DOB AS DATE, @AgeAt DATE)
RETURNS INTEGER
AS
BEGIN
RETURN (DATEDIFF(YYYY,@DOB,@AgeAt))
END
The function appears to have an error when it is called (underlined in red) with the prompt displaying "Procedure or function 'myprofile.udf_getAge' has too many arguments specified". When the function is called however, it operates correctly. An example of where I have used the function in a query reads:
SELECT
Forename + ' ' + Surname AS Name,
[*myprofile*].udf_getAge(DOB, GETDATE()) As Age
FROM
*myTable*
Does this apparent error make sense to anyone? As I say, it operates fine but it doesn't sit well with me having it identified as having 'too many arguments'.