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?

theduck
  • 2,589
  • 13
  • 17
  • 23
blathur
  • 187
  • 1
  • 8
  • You defined two function paramters. For function execution, you must add two parameter to function. Not one of them. Must be two.. – hsyn.ozkara Sep 20 '19 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... – blathur Sep 20 '19 at 14:08

0 Answers0