1 2003-07-10 2003 20 星期一
1 2003-07-11 2003 20 星期二
想要变成
--------------------
1 07/09/2003 2003 第20周(7/9-7/17)
1 07/10/2003 2003 第20周(7/9-7/17)
1 07/11/2003 2003 第20周(7/9-7/17)
请问:这个语句应该怎么去写?
答: if object_id('tablename') is not null drop table tablename
select 1 as time_id, '2003-07-09' as time_date, 2003 as [year], 20 as week_of_year, '星期日' as [day]
into tablename
union select 1, '2003-07-10', 2003, 20, '星期一'
union select 1, '2003-07-11', 2003, 20, '星期二'
------------------------------------------------
select time_id, time_date, [year], '第' + cast(week_of_year as varchar(2)) + '周('
+ cast(month(week_begin) as varchar(2)) + '/' + cast(day(week_begin) as varchar(2)) + '-'
+ cast(month(week_end) as varchar(2)) + '/' + cast(day(week_end) as varchar(2)) as week_of_year
from (select *, dateadd(day, 1 - datepart(weekday, time_date), time_date) as week_begin,
dateadd(day, 7 - datepart(weekday, time_date), time_date) as week_end from tablename) a
/*
文章来源于领测软件测试网 https://www.ltesting.net/