SQL function as default parameter value?

前端 未结 6 491
孤城傲影
孤城傲影 2020-12-13 11:45

I tried changing a default parameter value with this:

ALTER PROCEDURE [dbo].[my_sp]
@currentDate datetime = GETDATE()

and all the SQL pre-c

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 12:05

    I infer you're using Microsoft SQL Server from the square brackets in your example.

    From MSDN:

    Only a constant value, such as a character string; a scalar function (either a system, user-defined, or CLR function); or NULL can be used as a default.

    The function GETDATE() returns a different value from time to time, so it is not a constant expression.

提交回复
热议问题