需要五年的数据 像weekno,weekdateformat,年份,财政年度
但是需要一周的财政年度总是1,如
1,2015年3月28日 - 2016年4月3日,2016-2017,2016
/ procedure weekyearformat /
create PROCEDURE [dbo].[Proc_weekyearformat]
@WeekNum int
, @YearNum int
AS
BEGIN
SET NOCOUNT ON;
SET FMTONLY OFF ;
set @WeekNum=datepart(wk,getdate());
set @YearNum=datepart(yyyy,getdate())
declare @yearcout int =5;
SELECT *
FROM
-- once you have the @WeekNum and @YearNum set, the following calculates the date range.
(SELECT datepart(wk,DATEADD(wk,-10,getdate()))
as count1, convert(varchar(11),DATEADD(wk, DATEDIFF(wk, 6, '1/1/' + convert(char,@YearNum)) +
(@WeekNum-1), 0))+' - '+
convert(varchar(11),DATEADD(wk, DATEDIFF(wk, 5, '1/1/' + convert(char,@YearNum)) + (@WeekNum-1), -1))
as formatset,convert(varchar,@YearNum)+'-'+convert(varchar,@YearNum+1) as yearset,
convert(varchar,@YearNum) as yearone
)
AS StartOfWeek;
end
--exec Proc_weekyearformat 1,2016