0

In Microsoft SQL Server 2016, created a function with default argument, but it is not working as expected.

When calling select dbo.myTest(2), it is giving error:

An insufficient number of arguments were supplied for the procedure or function dbo.myTest.

CREATE FUNCTION dbo.myTest(@num1 INT, @num2 int = 1 )
RETURNS int
AS
BEGIN

   RETURN @num2

END

I am expecting to call the function with 1 argument also, What is it I am doing wrong here?

2
  • You defined two function paramters. For function execution, you must add two parameter to function. Not one of them. Must be two.. Commented Sep 20, 2019 at 14:04
  • that is why am giving default value for argument @num2 int = 1, so that I do not have to pass the value... Commented Sep 20, 2019 at 14:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.