Incorrect syntax near ')' calling stored procedure with GETDATE

Nat picture Nat · Mar 8, 2010 · Viewed 75.5k times · Source

Maybe I am having a moment of 'afternoon', but can anyone explain why I get

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.

When running

CREATE PROC DisplayDate 
    (@DateVar DATETIME) 
AS 
BEGIN
    SELECT @DateVar
END
GO

EXEC DisplayDate GETDATE();

Answer

Mitch Wheat picture Mitch Wheat · Mar 8, 2010

You can't pass in a function call as an argument to your stored procedure. Instead use an intermediate variable:

DECLARE @tmp DATETIME
SET @tmp = GETDATE()

EXEC DisplayDate @tmp;