日期:2014-05-18 浏览次数:20447 次
IF OBJECT_ID('F_getmonths') IS NOT NULL DROP FUNCTION F_getmonths GO CREATE FUNCTION F_getmonths (@n_date datetime ) RETURNS @tb_month table(第一天 datetime,最后一天 datetime) AS BEGIN declare @N_day int declare @first_date datetime,@last_date datetime set @n_day=datepart(dd,@n_date) if @n_day >25 begin set @first_date=cast(cast(year(@n_date) as varchar)+'-'+cast(month(@n_date)as varchar)+'-26' as datetime) set @last_date=cast(cast(year(@n_date) as varchar)+'-'+cast(month(dateadd(mm,1,@n_date))as varchar)+'-25' as datetime) end else begin set @first_date=cast(cast(year(@n_date) as varchar)+'-'+cast(month(dateadd(mm,-1,@n_date))as varchar)+'-26' as datetime) set @last_date=cast(cast(year(@n_date) as varchar)+'-'+cast(month(@n_date)as varchar)+'-25' as datetime) end insert @tb_month select @first_date,@last_date return END GO