在 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())