日期:2014-05-17 浏览次数:20441 次
create proc leaveoff
@year varchar(20),
@month varchar(20),
@dateStart datetime,
@dateEnd datetime
as
declare @days int --时间段内的天数
declare @date datetime
declare @date1 datetime
declare @condition varchar(200)
set @days = datediff (day,@dateStart,@dateEnd)+1--计算时间段内天数
set @date = convert(datetime,(@year+'-'+@month+'-'+convert(varchar(20),@days)))--得出最后一天
print @date
print @year
print @month
set @date1 = convert(datetime,(@year+'-'+@month+'-01'))--得出第一天
set @condition=(select
(case
when(datepart(year,PeopleLeave.leaveStartTime)=@year and datepart(month,PeopleLeave.leaveStartTime)=@month and
datepart(year,PeopleLeave.leaveEndTime)=@year and datepart(month,PeopleLeave.leaveEndTime)=@month)
then ('考勤日期 between '''+ CONVERT(varchar(12) , leaveStartTime, 102 ) +''' and '''+ CONVERT(varchar(12) , leaveEndTime, 102 )+'''')
when (datepart(year,PeopleLeave.leaveStartTime)=@year and datepart(month,PeopleLeave.leaveStartTime)=@month and
datepart(year,PeopleLeave.leaveEndTime)=@year and datepart(month,PeopleLeave.leaveEndTime)>@month)
then ('考勤日期 between '''+ CONVERT(varchar(12) , leaveStartTime, 102 ) +' and '+CONVERT(varchar(12) , @date, 102 )+'''')
when (datepart(year,PeopleLeave.leaveStartTime)=@year and datepart(month,PeopleLeave.leaveStartTime)<@month and
datepart(year,PeopleLeave.leaveEndTime)=@year and datepart(month,PeopleLeave.leaveEndTime)=@month)
then ('考勤日期 between '''+ CONVERT(varchar(12) , @date1, 102 ) +' and '+ CONVERT(varchar(12) , leaveEndTime, 102 )+'''')
end) condion from PeopleLeave)
print @condition
update temp set 考勤结果='请假' where 人员编号
in(select pid from PeopleLeave) and @condition
CREATE PROC leaveoff
@year VARCHAR(20) ,
@month VARCHAR(20) ,
@dateStart DATETIME ,
@dateEnd DATETIME
AS
DECLARE @days INT --时间段内的天数
DECLARE @date DATETIME
DECLARE @date1 DATETIME
DECLARE @condition VARCHAR(200)
SET @days = DATEDIFF(day, @dateStart, @dateEnd) + 1--计算时间段内天数
SET @date = CONVERT(DATETIME, ( @year + '-' + @month + '-'
&nbs