CREATEFUNCTIONGetVac(@Startdatetime,@Enddatetime)
RETURNSintegerAS
BEGIN
declare
@intNuminteger,
@intAllDayinteger,
@iinteger,
@intWeekDayinteger,
@tempDateTimedatetime,
@intVacinteger
select@intAllDay=DateDiff(dd,@Start,@End)
select@i=0
select@intVac=0
while(@i<@intAllDay)
begin
select@tempDateTime=DateAdd(dd,@i,@Start)
select@intWeekDay=datepart(dw,@tempDateTime)-1
if(@intWeekDay=6)or(@intWeekDay=0)
begin
select@intVac=@intVac+1
end
select@i=@i+1
end
return@intVac
END
好的,这个函数天生今后,我们就能够利用这个函数了,好比:
selectaa=dbo.GetVac(2000-12-1000:00:00.000,2000-12-1800:00:00.000)
失掉的了局是:3呵呵