Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save strvmarv/d5c6b493f4cbc66774615b8032820e9d to your computer and use it in GitHub Desktop.
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
@szilardd
Copy link

@partMin, @partStart and @partEnd variables are not used after being assigned a value. Just a heads up :)

@strvmarv
Copy link
Author

strvmarv commented Jul 7, 2016

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