一个简单的问题
时间:2011-12-14
来源:互联网
--自定义一个函数,要求函数计算给定出生日期的年龄:
create function fun_age(@birth as datetime)
returns int
as
begin
declare @age int
set @age=datediff(yy,@birth,getdate())
--set @age=year(getdate())-year(@birth)
return @age
--return (year(getdate())-year(@birth))
end
drop function fun_ageselect dbo.fun_age('1990-04-23') as 年龄
为什么在2000版本上报错(2005以上都可以),提示getdate()函数
错误。请问有没有方法能在2000版本上正确使用这个函数
create function fun_age(@birth as datetime)
returns int
as
begin
declare @age int
set @age=datediff(yy,@birth,getdate())
--set @age=year(getdate())-year(@birth)
return @age
--return (year(getdate())-year(@birth))
end
drop function fun_ageselect dbo.fun_age('1990-04-23') as 年龄
为什么在2000版本上报错(2005以上都可以),提示getdate()函数
错误。请问有没有方法能在2000版本上正确使用这个函数
作者: TravyLee 发布时间: 2011-12-14
因为2000里的自定义函数内不能使用GETDATE(),而2005可以.
作者: liangCK 发布时间: 2011-12-14
是不可以的
需要用一個視圖
SQL code
函數調用視圖實現
需要用一個視圖
SQL code
Create view Dt as select dt=getdate()
函數調用視圖實現
作者: roy_88 发布时间: 2011-12-14
SQL code
CREATE VIEW v_GETDATE AS SELECT GETDATE() AS curDate; GO create function fun_age(@birth as datetime) returns int as begin declare @age int SELECT @age=datediff(yy,@birth,curDate) FROM v_GETDATE; return @age end
作者: liangCK 发布时间: 2011-12-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28