Situatie
Mai jos este o functie ce primeste doi parametrii, al doilea definind data din anul de referinta si primul definind numarul saptamanii din anul de referinta. In functie de acesti parametrii functia returneaza ziua cu care se sfarseste saptamana definita de primul parametru.
Solutie
create function End_of_week_fct
(@week_number int, @today datetime)
returns datetime
as
begin
declare @end_week datetime
declare @start_week datetime
set @today = dateadd(wk, @week_number- datepart(wk,@today), @today)
set @start_week = dateadd(d, 1 – DATEPART(dw, @today), @today)
set @end_week = dateadd(d,7,@start_week )
return @end_week
end
— select dbo.End_of_week_fct(1,getdate())
Leave A Comment?