Last active
July 7, 2016 15:11
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION [dbo].[udf_GetDayOfTheYearRange_FromDate] (@startDate DATETIME, @endDate DATETIME) | |
RETURNS @results TABLE (Number SMALLINT) AS | |
BEGIN | |
DECLARE @partMin SMALLINT = 1 | |
DECLARE @partMax SMALLINT = 365 | |
DECLARE @expectedCount INT = DATEDIFF(DAY, @startDate, @endDate) | |
IF (@expectedCount < 0) | |
SET @expectedCount = @partMax + @expectedCount | |
DECLARE @count INT = 0 | |
DECLARE @current SMALLINT = [dbo].[udf_GetDayOfTheYear](@startDate) | |
WHILE (@count <= @expectedCount) | |
BEGIN | |
INSERT INTO @results (Number) VALUES (@current) | |
IF (@current >= @partMax) | |
SET @current = @partMin | |
ELSE | |
SET @current = @current + 1 | |
SET @count = @count + 1; | |
END | |
RETURN | |
END |
Ack, sorry about that, some copy/paste fails on my part...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@partMin, @partStart and @partEnd variables are not used after being assigned a value. Just a heads up :)