Reputation: 4927
I have a stored procedure like below:
ALTER procedure [dbo].[test_stored_procedure]
@id nvarchar(20),
@datefm datetime,
@dateto datetime
as
...
end
Then I'm trying to call the above stored procedure using below SQL:
exec test_stored_procedure @searchKey, cast('1900-01-01 00:00:00' as datetime), cast('1900-01-01 00:00:00' as datetime)
But when executed, I got the below error:
Incorrect syntax near '1900-01-01 00:00:00'.
How to fix this?
Upvotes: 1
Views: 2471
Reputation: 176189
You need use:
DECLARE
@date_start DATETIME = '1900-01-01 00:00:00'
,@date_stop DATETIME = '1900-01-01 00:00:00';
EXEC test_stored_procedure @searchKey, @date_start, @date_stop;
Or:
EXEC test_stored_procedure @searchKey, '1900-01-01 00:00:00', '1901-01-01 00:00:00';
It is because you cannot use function on parameters with EXEC
See doc. You can pass only:
[ [ @parameter = ] { value | @variable [ OUTPUT ] | [ DEFAULT ]
Upvotes: 6