select max(id) from table where year(datetime)=year(getdate())
是有存储过程中,好像不能用getdate()呀
在存储过程中可以用getdate(),但在自定义函数中不能用。
若要在函数中使用,如下处理: 1:先建一个视图 create view vGetdate as select getdate() as today go /* 2:用自定义函数来得到单号(因自定函数内不能用getdate()来得到当前日期,要用到上面的视图) */ create function ... returns ... As begin select today from vGetdate ... end go
1:先建一个视图
create view vGetdate
as
select getdate() as today
go
/* 2:用自定义函数来得到单号(因自定函数内不能用getdate()来得到当前日期,要用到上面的视图) */
create function ...
returns ...
As
begin
select today from vGetdate
...
end
go