/* FUNCTION:根据周数返回该周最后日期 返回:日期 输入1:年输入2:周数 */
CREATE function [dbo].[uf_get_Week2Day](@intYear integer,@intWeek integer)
returns datetime
as
begin
declare @dateFirstDayOfYear datetime
declare @dateFirstDayOfWeek datetime
declare @dateLastDayOfWeek datetime
set @dateFirstDayOfYear=convert(smalldatetime,convert(varchar(4),@intYear) + '-1-1')
set @dateFirstDayOfWeek=dateadd(day,1-datePart(weekday,@dateFirstDayOfYear),dateAdd(week,@intWeek-
1,@dateFirstDayOfYear))
set @dateLastDayOfWeek=dateadd(day,6,@dateFirstDayOfWeek)
RETURN @dateLastDayOfWeek
end
GO
标量值函数的调用
select dbo.uf_get_Wee