This question already has answers here:
Incorrect syntax near ')' calling stored procedure with GETDATE

(2个答案)


3年前关闭。




我正在测试存储过程,并想提交“GETDATE()”函数代替参数:
DECLARE @return_value int

EXEC @return_value = my_stored_procedure
        @MyId = 1,
        @MyDateField = GETDATE()

SELECT  'Return Value' = @return_value
GO

SQL Server 2005抱怨以下错误:



有人在乎这件事吗?

最佳答案

每个MSDN

Execute a stored procedure or function
[ { EXEC | EXECUTE } ]
    {
      [ @return_status = ]
      { module_name [ ;number ] | @module_name_var }
        [ [ @parameter = ] { value
                           | @variable [ OUTPUT ]
                           | [ DEFAULT ]
                           }
        ]
      [ ,...n ]
      [ WITH RECOMPILE ]
    }
[;]

    Execute a character string
    { EXEC | EXECUTE }
        ( { @string_variable | [ N ]'tsql_string' } [ + ...n ] )
        [ AS { LOGIN | USER } = ' name ' ]
    [;]

    Execute a pass-through command against a linked server
    { EXEC | EXECUTE }
        ( { @string_variable | [ N ] 'command_string [ ? ]' } [ + ...n ]
            [ { , { value | @variable [ OUTPUT ] } } [ ...n ] ]
        )
        [ AS { LOGIN | USER } = ' name ' ]
        [ AT linked_server_name ]
    [;]

注意,@ parameter可以指定值或变量,也可以指定Default。因此,您必须将变量的值设置为GetDate()(如其他人所指定的)并使用该变量。

高温超导

关于sql-server - 执行存储过程时将函数用作参数? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5967035/

10-15 16:01