This is a function that returns a table containing the last days of months in a specified number
of following years.
***************************************
CREATE FUNCTION dbo.fnListOfLastDatesMonth
(@dtmStartDate datetime, @inyCountYears tinyint)
RETURNS @tblDates table (LastDate datetime) AS
BEGIN
declare @dtmEndDate datetime
declate @dtmDate datetime
set @dtmEndDate = DATEADD(year, @inyCountYears, @dtmStartDate)
set @dtmDate = @dtmStartDate
while @dtmDate < @dtmEndDate
begin
insert into
@tblDates
values(dbo.fnLastDateOfMonth(dtmDate))
set @dtmDate
= DATEADD(month, 1, @dtmDate)
end
RETURN
END
|