[求助]关于SQL自定义函数的问题
编写一个自定义函数,根据出生日期计算年龄 .怎样实现?
create view v_GETDATE
as
select dt=getdate()
go
create function dbo.f_getAge(@date datetime)
returns int
as
begin
return (select datediff(year,@date,dt) from v_GETDATE)
end
go
declare @dt datetime
set @dt='1988-01-02'
select '你的年龄是:'+cast(dbo.f_getAge(@dt) as varchar)+'岁'
drop function f_getAge
drop view v_GETDATE