Groups | Search | Server Info | Keyboard shortcuts | Login | Register


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

Parameters with default values in functions

Path csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Anton Shepelev <anton.txt@g{oogle}mail.com>
Newsgroups comp.databases.ms-sqlserver
Subject Parameters with default values in functions
Date Fri, 1 Mar 2024 13:53:10 +0300
Organization A noiseless patient Spider
Lines 36
Message-ID <20240301135310.27742ad2db04a98c37f5099e@g{oogle}mail.com> (permalink)
MIME-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
Injection-Info dont-email.me; posting-host="eeceec7014f61528356a85bf77e35708"; logging-data="1268270"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qnhxKkCpmICEeS7XbcGsOREwnqcgnNp0="
Cancel-Lock sha1:Jy9TnCq5VYVq14TDKq1NFKebvss=
X-Newsreader Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Xref csiph.com comp.databases.ms-sqlserver:2236

Show key headers only | 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