我一直在写SQL Server中的用户定义函数:字符串转换为函数SQL Server日期时间
它看起来像这样:
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')
当我尝试运行此,我得到的以下错误:
Conversion failed when converting the nvarchar value '08/17/2010 4:30' to data type int.
我在做什么错?
为什么nvarchar?你会在你的日期字符串中有变音符号和日元符号吗? –
否..它可以是varchar ...... – user838359
是你没有使用正确的数据类型? – NullUserException