SQL function as default parameter value?

前端 未结 6 510
孤城傲影
孤城傲影 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:30

    Default value for stored procedures parameter have to be constants. You'd need to do the following...

    ALTER Procedure [dbo].[my_sp]
    @currentDate datetime = null
    AS
    IF @currentDate is null
    SET @currentDate = getdate()
    

提交回复
热议问题