Groups | Search | Server Info | Login | Register


Groups > comp.databases.ms-sqlserver > #2236

Parameters with default values in functions

From Anton Shepelev <anton.txt@g{oogle}mail.com>
Newsgroups comp.databases.ms-sqlserver
Subject Parameters with default values in functions
Date 2024-03-01 13:53 +0300
Organization A noiseless patient Spider
Message-ID <20240301135310.27742ad2db04a98c37f5099e@g{oogle}mail.com> (permalink)

Show all headers | View raw


Hello, all

MSSQL allows default values in parameters to functions:

  CREATE FUNCTION test( @v INT = 1 )
  RETURNS TABLE AS
  RETURN  ( SELECT @v AS v )

but will not let me use them -- the invocation

  SELECT * FROM test()

fails with:

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

The documentation says it should work:

  -- Transact-SQL Inline Table-Valued Function Syntax
  CREATE [ OR ALTER ] FUNCTION [ schema_name. ] function_name
  ( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type [ NULL ]
      [ = default ] [ READONLY ] }
      [ ,...n ]
    ]
  )

  The value of each declared parameter must be supplied by
  the user when the function is executed, unless a default
  for the parameter is defined.

What am I doing wrong on my MSSQL v. 13?

-- 
()  ascii ribbon campaign -- against html e-mail
/\  www.asciiribbon.org   -- against proprietary attachments

Back to comp.databases.ms-sqlserver | Previous | NextNext in thread | Find similar


Thread

Parameters with default values in functions Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-03-01 13:53 +0300
  Re: Parameters with default values in functions Erland Sommarskog <esquel@sommarskog.se> - 2024-03-01 23:18 +0100
    Re: Parameters with default values in functions Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-03-05 11:36 +0300
      Re: Parameters with default values in functions Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-03-05 11:39 +0300

csiph-web