CREATE FUNCTION GetVac(@Start datetime,@End datetime) RETURNS integer AS BEGIN declare @intNum integer,@intAllDay integer,@i integer,@intWeekDay integer,@tempDateTime datetime,@intVac integerselect @intAllDay=DateDiff(dd,@Start,@End)select @i=0select @intVac=0while(@i<@intAllDay)beginselect @tempDateTime=DateAdd(dd,@i,@Start)select @intWeekDay=datepart(dw,@tempDateTime)-1if(@intWeekDay=6) or (@intWeekDay=0)beginselect @intVac=@intVac 1endselect @i=@i 1endreturn @intVacEND好的,这个函数生成以后,我们就可以使用这个函数了,比如:select aa=dbo.GetVac(2000-12-10 00:00:00.000,'2000-12-18 00:00:00.000')得到的结果是:3 呵呵