I have a stored proc which looks like this:
CREATE PROC [dbo].[UpdateLastCleanDatesNormalSchedule]
@BaseDate DATETIME = NULL
AS
IF @BaseDate IS NULL
SET @BaseDate=GETDATE()
UPDATE Locations
SET LastCleaned=dbo.fnFindTheLastDay(vw.CleanDay,@BaseDate,LastCleaned)
FROM Locations
INNER JOIN vwMostRecentCleanDay vw ON
Locations.NormalFrequencyCode=vw.FrequencyCode
The code is pretty simple, as you can see, calling a function to update data for a street-cleaning database with the date when the location was last cleaned.
Here's my problem. This works:
EXEC dbo.UpdateLastCleanDatesNormalSchedule
But this doesn't:
EXEC dbo.UpdateLastCleanDatesNormalSchedule GETDATE()
and nor does this:
EXEC dbo.UpdateLastCleanDatesNormalSchedule @BaseDate=GETDATE()
Either of these result in the error
Incorrect syntax near ')'.
and if I hover over the wiggly red line, by the closing bracket of the call to GETDATE(), the tooltip reports " Incorrect syntax near ')'. Expecting SELECT or '('.
If I want to pass in a specific date and try this:
EXEC dbo.UpdateLastCleanDatesNormalSchedule CONVERT(Datetime,'01 September 2016')
I get the error
Incorrect syntax near the keyword 'CONVERT'.
But if I pass in the date as a pure string:
EXEC dbo.UpdateLastCleanDatesNormalSchedule '01 September 2016'
then it works.
In desperate hope that this was some kind of glitch rather than an error on my part, I tried dropping and recreating the proc, but no luck.
I'm very confused. Can anyone help?