--以工作日計算起始年假的計算時間範圍
declare @settoday smalldatetime,@birthday smalldatetime,@year varchar(10),@month varchar(10),@day varchar(10),@enddate datetime,@stardate datetime,@AnnualNumber int,@AnnualTotal int,@Surplus int
set @settoday='2013-05-04'--現在日期
set @birthday='2004-04-26' ---進公司日期
set @year=DateName(Year,@settoday)
set @month=DateName(Month,@birthday)
set @day=DateName(Day,@birthday)
--
set @enddate=cast(@year+'-'+@month+'-'+@day as datetime)
select @month
select @enddate
if(@enddate>=@settoday)
begin
set @stardate=dateadd(year,-1,@enddate) --減一年
end
else
begin
set @enddate=dateadd(year,1,@enddate)
set @stardate=cast(@year+'-'+@month+'-'+@day as datetime)
end
select @stardate AS '起始計算日期'
select @enddate AS '結束計算日期'