All pastes #792655 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-21 16:33 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
    
SET @tap = 0
SET @x = 1995

WHILE (@x < 2009)

BEGIN
    
    SET @nov = '1/11/' + CAST(@x as VARCHAR )
    SET @feb = '1/2/' + CAST((@x + 1) as VARCHAR )
    SET @may = '15/5/' + CAST((@x + 1) as VARCHAR )
    
    If @STPRG_START <= @nov And @STPRG_END >= @may Then SET @tap = @tap + 3
    If @STPRG_START <= @nov And @STPRG_END >= @feb Then SET @tap = @tap + 2
    If @STPRG_START <= @nov And @STPRG_END >= @nov Then SET @tap = @tap + 1
    If @STPRG_START <= @feb And @STPRG_END >= @may Then SET @tap = @tap + 2
    If @STPRG_START <= @feb And @STPRG_END >= @feb Then SET @tap = @tap + 1
    If @STPRG_START <= @may And @STPRG_END >= @may Then SET @tap = @tap + 1
    
    SET @x = @x + 1

END
    
    If @tap = 0 Then SET @tap = 1
    
    Return @tap
END