2

我想将 GetDate() 设置为默认参数值。但它显示错误。下面是我的代码块:

Create Proc XYS
(
   @myDate datetime = GetDate()  //error

)
AS
SET @myDate = GetDate() // i can do this but neither i want this nor I want to 
                           pass current date from front end or upper layer


....
....

据我所知,此级别不支持函数/动态值,而是允许我们使用硬编码值。任何解决方法?

4

2 回答 2

2

建议使用一个值(例如 0 = 最小日期时间),然后在您的存储过程中检查它:

Create Proc XYS
(
   @myDate datetime = 0)
AS
BEGIN
    IF @myDate = 0
        SET @myDate = GetDate()

    // ...
END
于 2013-08-13T07:57:06.810 回答
0

我并不是说这是世界上最好的主意,但它对我有用:

CREATE VIEW dbo.V_GetDate
AS
SELECT     GETDATE() AS TheDate

然后

Create Proc XYS
AS
declare @myDate datetime
Select @myDate = TheDate from dbo.V_GetDate
于 2013-08-13T09:56:10.590 回答