1

I am running my stored procedure that takes only one argument of type DATE. The name of the argument is DateParam

EXEC [MyDBNAME].[dbo].[SPName] @DateParam = CONVERT(DATE, GETDATE());

But I get the following error:

Incorrect syntax near the keyword 'CONVERT'.

I have seen this error in many other questions here as well as other forums. But I did not find one that answers the problem. Thanks for looking!

disasterkid
  • 6,948
  • 25
  • 94
  • 179

1 Answers1

4

SQL Server doesn't parse expressions in exec. So assign to a parameter:

DECLARE @today DATE = CONVERT(DATE, GETDATE());

EXEC [MyDBNAME].[dbo].[SPName] @DateParam = @today;

I imagine that Microsoft has a good reason for this limitation -- such as parsing ambiguities in the line. It is a pain.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786