Situatie
Pentru cazurile in care este necesar am facut o functie in sql ce primeste ca parametru un an calendaristic si returneaza data, din acel an, cand pica sarbatoarea de Paste.
Solutie
–select dbo.Paste_fct (2021)
alter FUNCTION dbo.Paste_fct (@An INT)
RETURNS DATE
AS
BEGIN
DECLARE @Data DATE, @c INT, @n INT, @i INT, @k INT, @j INT, @l INT, @m INT, @d INT
SET @n = @An – 19 * (@An / 19)
SET @c = @An / 100
SET @k = (@c – 17) / 25
SET @i = @c – @c / 4 – (@c – @k) / 3 + 19 * @n + 15
SET @i = @i – 30 * (@i / 30)
SET @i = @i – (@i / 28) * (1 – (@i / 28) * (29 / (@i + 1)) * ((21 – @n) / 11))
SET @j = @An + @An / 4 + @i + 2 – @c + @c / 4
SET @j = @j – 7 * (@j / 7)
SET @l = @i – @j
SET @m = 3 + (@l + 40) / 44
SET @d = @l + 28 – 31 * (@m / 4)
SET @Data = convert(date, CAST(@An AS VARCHAR) + ‘-‘ + CAST(@m AS VARCHAR) + ‘-‘ + CAST(@d AS VARCHAR), 102)
RETURN @Data
END
GO
Leave A Comment?