I have been writing a user-defined function in SQL Server:
It looks like this :
CREATE FUNCTION FormatDate(@fromtime nvarchar(50))
RETURNS DATETIME
AS
BEGIN
DECLARE @tempfrom datetime
DECLARE @tempto nvarchar(50)
set @tempfrom = Convert(datetime, @fromtime, 100)
RETURN @tempfrom
END
select dbo.FormatDate('08/17/2010 4:30')
When I try to run this, I get the following error:
Conversion failed when converting the nvarchar value ’08/17/2010 4:30′ to data type int.
What am I doing wrong?
Why are you using style 100?