Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


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

Re: Parameters with default values in functions

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver
Subject Re: Parameters with default values in functions
Date 2024-03-01 23:18 +0100
Organization Erland Sommarskog
Message-ID <XnsB128ED1216A95Yazorman@127.0.0.1> (permalink)
References <20240301135310.27742ad2db04a98c37f5099e@g{oogle}mail.com>

Show all headers | View raw


Anton Shepelev (anton.txt@g{oogle}mail.com) writes:
> 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.
> 

I'm about to say that I don't even want to talk about this, because
it is so stupid. That is, you must supply the DEFAULT keyword explicitly:

SELECT * FROM dbo.test(DEFAULT)

Which of course defies quite much of the idea with a default parameter 
when you want to add a new parameter to an existing function.

Here is a feedback item you can vote for:
https://feedback.azure.com/d365community/idea/95dbf609-5a25-ec11-b6e6-
000d3a4f0da0

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next 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