February 20, 2005 at 7:00 pm
Executing something just like the Proc below gave me "Error 241: Syntax error converting datetime from character string." As you can see, I'm trying to default that one parameter to today's date. I can't find a rule governing why this won't work when passed DEFAULT as the parameter. Passing a regular date works fine. I get the same error even if I set the parameter up as a varchar. How do I get this to work when passed DEFAULT from my frontend app?
I tried to CAST or CONVERT the parameter in various parts of the proc, but that still won't do it.
***************************************************
CREATE PROC NWtest @endDate datetime=getdate
AS
SELECT OrderDate
FROM Northwind.dbo.Orders
WHERE OrderDate<@enddate
Order By OrderDate
GO
EXEC NWtest DEFAULT
GO
***************************************************
Many thanks,
-Ed H.
February 20, 2005 at 8:12 pm
As per Books Online, the default must be a constant or NULL.
You could re-code your stored procedure like this,
CREATE PROC NWtest @endDate datetime = NULL ASIF @enddate IS NULL SET @endDate = GetDate()SELECT OrderDate FROM Northwind.dbo.Orders WHERE OrderDate<@enddate Order By OrderDateGO
--------------------
Colt 45 - the original point and click interface
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply