I tried changing a default parameter value with this:
ALTER PROCEDURE [dbo].[my_sp]
@currentDate datetime = GETDATE()
and all the SQL pre-c
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.
You can try as follow:
Set @CurrentDate=IsNull(@CurrentDate,GetDate())
That value is not deterministic and cannot be used
Suggestion:
Set the default to NULL
Do the Default GETDATE()
in the front end.
I don't think that is possible, you have to use a literal (constant) value as the default.
However you can do this:
Set @currentDate = Coalesce(@currentDate , GetDate())
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()