0

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'.

2 Answers 2

1

SQL Server Management Studio (SSMS) caches the UDF signature to apply syntax highlighting, if the function signature got changed within the same session you might get that behavior. Please try to restart SSMS and the "error" should go away.

Sign up to request clarification or add additional context in comments.

2 Comments

I have just tried that after finishing writing the question. Sometimes it is the most simple things that we overlook; it worked. I will leave the question rather than deleting it for anyone who may encounter the same problem in the future, even if it is an embarrassment for me!
Restarting SSMS is a big hammer. A much smaller one is to try disabling and re-enabling Intellisense from the "Query" menu (or from the context menu in the window you're working in).
1

Try pressing Ctrl+Shift+R in SSMS to refresh.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.