All pastes #792626 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-21 16:11 UTC
rendered paste body
CREATE FUNCTION TOTAL_TAP(@STPRG_START Date, @STPRG_END Date)
RETURNS integer
AS
BEGIN
Declare @nov As Date
Declare @feb As Date
Declare @may As Date
Declare @tap As Integer
Declare @x As Integer
    
    @tap = 0
    
    For @x = 1995 To 2009
    
    @nov = DateValue("1/11/" & Str$(x))
    @feb = DateValue("1/2/" & Str$(x + 1))
    @may = DateValue("15/5/" & Str$(x + 1))
    
    If @STPRG_START <= @nov And @STPRG_END >= @may Then
        @tap = @tap + 3
    ElseIf @STPRG_START <= @nov And @STPRG_END >= @feb Then
        @tap = @tap + 2
    ElseIf @STPRG_START <= @nov And @STPRG_END >= @nov Then
        @tap = @tap + 1
    ElseIf @STPRG_START <= @feb And @STPRG_END >= @may Then
        @tap = @tap + 2
    ElseIf @STPRG_START <= @feb And @STPRG_END >= @feb Then
        @tap = @tap + 1
    ElseIf @STPRG_START <= @may And @STPRG_END >= @may Then
        @tap = @tap + 1
    Else
        @tap = @tap
    End If
    
    Next @x
    
    If @tap = 0 Then @tap = 1
    
    Return @tap
END