代码之家  ›  专栏  ›  技术社区  ›  geoff swartz

sql作业和日期时间参数

  •  2
  • geoff swartz  · 技术社区  · 16 年前

    Incorrect syntax near ')' . 执行它的调用是:

    exec CreateHeardOfUsRecord getdate()
    

    exec CreateHeardOfUsRecord '4/1/2010' 很好用。你知道为什么我不能用吗 getdate() 在这种情况下?谢谢。

    4 回复  |  直到 14 年前
        1
  •  3
  •   MartW    16 年前

    与Exec一起传递的参数 must either be constants or variables . GetDate()被归类为函数。您需要声明一个变量来保存GetDate()的结果,然后将其传递给存储过程。

    提供的值必须是常量 或变量;不能指定 函数名作为参数值。 系统变量,如@@spid。

        2
  •  1
  •   KM.    16 年前

    EXECUTE (Transact-SQL)

    [ { EXEC | EXECUTE } ]
        { 
          [ @return_status = ]
          { module_name [ ;number ] | @module_name_var } 
            [ [ @parameter = ] { value 
                               | @variable [ OUTPUT ] 
                               | [ DEFAULT ] 
                               }
    

    只能传入常量值、变量或DEFAULT子句

    试一试:

    create procedure xy_t
    @p datetime
    as
    select @p
    go
    
    exec xy_t GETDATE()
    

    输出:

    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near ')'.
    
        3
  •  0
  •   Broken Link    16 年前

    尝试传递Convert(varchar,GetDate(),101)

        4
  •  0
  •   Mike    16 年前

    create procedure xy_t 
    @p datetime 
    as 
    select @p 
    go 
    
    declare @date datetime
    
    set @date = getdate() 
    
    exec xy_t @date