server| function In fact, this function is not provided by SQL Server, is tofu written, we do not because of tofu piece of everyone
To use a stone to hit tofu: In fact, since this function generated after we use, it is impossible to distinguish between this
Whether the function is SQL Server or a custom function, this is one of the new features that SQL2K brings to us
Let's take a look at the meaning of this function, in fact, the person who originally asked me for this function is blue, but there was no sql2k,
Now that I've got sql2k, I've found some time to write this function. The function is in any two
Days to get rest between time. At present, only two repair days are processed:
Okay, let's take a look at this function, and by the way, we can learn to use this new feature of SQL2K.
CREATE FUNCTION Getvac (@Start datetime, @End datetime)
RETURNS Integer AS
BEGIN
Declare
@intNum Integer,
@intAllDay Integer,
@i Integer,
@intWeekDay Integer,
@tempDateTime datetime,
@intVac integer
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
OK, after this function is generated, we can use this function, for example:
Select Aa=dbo. Getvac (2000-12-10 00:00:00.000, ' 2000-12-18 00:00:00.000 ')
The result is: 3 hehe