不知错在何处?

sunbaoguo 2004-05-08 08:38:01
我编了这样一个函数,可是总有错,我实在不知错在何处?
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'。


好痛苦,这样一个简单的函数就是挑不出错在哪?
...全文
71 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
smalldeer 2004-05-08
  • 打赏
  • 举报
回复

create view vGetdate
as
select getdate() as today

使用

select convert(varchar(8),today,112 )from vGetdate
sunbaoguo 2004-05-08
  • 打赏
  • 举报
回复
Thank you very much.
I'll try to use the other ways.
But how about the other Functions?
DontWorry 2004-05-08
  • 打赏
  • 举报
回复
Can't Using getDate() method In Function.
sunbaoguo 2004-05-08
  • 打赏
  • 举报
回复
up

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧