sqlServer2000 中自定义函数中 getdate() 函数不识别

 

在 SQL Server 2008 中,自定义 函数 :

  

Create function CurrentMonthFirstDay()
returns Datetime
as
begin
 DECLARE @FistDayOfCurrentMonth DATETIME
 SET @FistDayOfCurrentMonth = DATEADD(mm,DATEDIFF(mm,0,getdate()),0) 
 return @FistDayOfCurrentMonth
end

  发现在2000中 不能运行, 首先 getedate() 不识别   ----- 改为 dbo.getdate().  可用生产了,但是不能执行,还是dbo.getdate() 的问题。

在网上找了下解决办法 。

 

将getdate() 作为参数传人:

 

Create function CurrentMonthFirstDay( @dt DATATIME)
returns Datetime
as
begin
 DECLARE @FistDayOfCurrentMonth DATETIME
 SET @FistDayOfCurrentMonth = DATEADD(mm,DATEDIFF(mm,0,dt),0) 
 return @FistDayOfCurrentMonth
end

select  dbo.CurrentMonthFirstDay(getdate())

  

posted @ 2012-12-04 11:29  googlg  阅读(1196)  评论(0编辑  收藏  举报