I have currently written a small UDF (Table Value Type) to return a table
of dates between a start and end date. Start and End dates are already retrieved from another table.
Start_End_Table
WeekNumber | Start Date | End Date
Function:
CREATE FUNCTION [dbo].[DatesBetween](@startDate datetime, @endDate datetime)
RETURNS @dates TABLE (
DateValue datetime NOT NULL
)
AS
BEGIN
WHILE (@startDate <= @endDate) BEGIN
INSERT INTO @dates VALUES (@startDate);
SET @startDate = DATEADD(day, 1, @startDate);
END;
RETURN;
END;
Until now, I have been using this function in the following manner,
SELECT * FROM [dbo].[DatesBetween](@startDate datetime, @endDate datetime);
Going forward I need to get start, end dates from Start_End_Date table and call the function. Thus I do not think returning a table
is an option any longer. How can I get this function to return an array of dates instead of a table? Or is there any other way I could wrap this up?