不知错在何处?
我编了这样一个函数,可是总有错,我实在不知错在何处?
create function getmessageid()
--2004-05-08
--get the id of message
returns char(11)
as
begin
declare @id int,@idofmessage char(11)
--得到左侧的基本位编码
set @idofmessage=right('0000'+cast(year(getdate()) as varchar),4)+right('000'+cast(month(getdate()) as varchar),2)+right('000'+cast(day(getdate()) as varchar),2)
--数列数
select @id=count(idofmessage) from message
where year(dateofget)=year(getdate()) and month(dateofget)=month(getdate()) and day(dateofget)=day(getdate())
--赋值
if @id=0
begin
set @idofmessage=@idofmessage+'001'
end
else
begin
set @idofmessage=@idofmessage+right('0000'+cast(@id+1 as varchar),3)
end
return(@idofmessage)
end
服务器: 消息 443,级别 16,状态 1,过程 getmessageid,行 10
在函数内不正确地使用了 'getdate'。
服务器: 消息 443,级别 16,状态 1,过程 getmessageid,行 13
在函数内不正确地使用了 'getdate'。
好痛苦,这样一个简单的函数就是挑不出错在哪?