每个课程表的有效日期生成器

时间:2019-04-26 17:47:52

标签: sql sql-server

我有一个@course_schedule表,其中列出了所有课程名称和课程表。 那里有2项父系课程,所有其他课程均从日程安排上有所变化。

父母课程是非常基础的课程,除周末和节假日外,每天都有课程。

所有有效的上课日期都在表@parent_course_dates中,假期模式可能会有一些变化 因此会捕获两个父课程的有效日期。

还有一个表@alldates,其中日期数据是用dayname捕获的。

我想创建将生成的逻辑

lecture_dates lab_dates 疑问日期 Any_other_date

按照表@course_schedule中提到的每种日期类型的描述列。日期将按照家长的课程表安排 所有工作日(星期一至星期五)的日程安排,而@all_dates表则用于任何周末日期(星期六)。

如果@parent_course_dates表中没有任何工作日(周一至周五),则表示该天将是假日,不应为 在这种情况下,考虑上课的日期应该根据说明来选择下一个或上一个日期,即如果说明是 第三个星期四之后的星期一,星期一是假期,那么如果星期二又是假期,那么应该选择星期二 应该选择星期三。

如果定义类似第三个星期四之前的星期三,并且星期三是假日,则应该选择星期二。

在星期六的情况下,假期不得有任何影响。

以下是示例数据。

     declare @course_schedule table (id int, course_name varchar(100), parent_course_id int, course_type char(5),
     lecture_schedule_desc varchar(500), lab_schedule_desc varchar(500),doubts_session_desc varchar(100), 
     active_in_months varchar(100) )

     declare @parent_course_dates table (id int identity, course_id int , valid_date int )

     declare @alldates table (valid_date int,[dayname] varchar(100))

     insert into @course_schedule 
     values(101, 'dax_course', 1, 'c1','Monday after third thursday of month in active_in_months'
     ,'wednesday before third thursday of month in active_in_months' ,'saturday after second friday of month in active_in_months' ,'1,2,3')

     insert into @course_schedule 
     values(111, 'dax2_course', 1, 'c1','Tuesday after second thursday of month in active_in_months'
     ,'monday after third friday of month in active_in_months' ,'Friday after second monday of month in active_in_months' ,'3,4')

     insert into @course_schedule 
     values(201, 'ml_course', 35, 'c1','Monday after third thursday of month in active_in_months'
     ,'wednesday before third thursday of month in active_in_months' ,'saturday after second monday of month in active_in_months' ,'1,2')


    insert into @parent_course_dates values('1 ','20190102')
    insert into @parent_course_dates values('1 ','20190103')
    insert into @parent_course_dates values('1 ','20190104')
    insert into @parent_course_dates values('1 ','20190107')
    insert into @parent_course_dates values('1 ','20190108')
    insert into @parent_course_dates values('1 ','20190109')
    insert into @parent_course_dates values('1 ','20190110')
    insert into @parent_course_dates values('1 ','20190111')
    insert into @parent_course_dates values('1 ','20190114')
    insert into @parent_course_dates values('1 ','20190115')
    insert into @parent_course_dates values('1 ','20190116')
    insert into @parent_course_dates values('1 ','20190117')
    insert into @parent_course_dates values('1 ','20190118')
    insert into @parent_course_dates values('1 ','20190121')
    insert into @parent_course_dates values('1 ','20190122')
    insert into @parent_course_dates values('1 ','20190123')
    insert into @parent_course_dates values('1 ','20190124')
    insert into @parent_course_dates values('1 ','20190125')
    insert into @parent_course_dates values('1 ','20190128')
    insert into @parent_course_dates values('1 ','20190129')
    insert into @parent_course_dates values('1 ','20190130')
    insert into @parent_course_dates values('1 ','20190131')
    insert into @parent_course_dates values('1 ','20190201')
    insert into @parent_course_dates values('1 ','20190204')
    insert into @parent_course_dates values('1 ','20190205')
    insert into @parent_course_dates values('1 ','20190206')
    insert into @parent_course_dates values('1 ','20190207')
    insert into @parent_course_dates values('1 ','20190208')
    insert into @parent_course_dates values('1 ','20190211')
    insert into @parent_course_dates values('1 ','20190212')
    insert into @parent_course_dates values('1 ','20190213')
    insert into @parent_course_dates values('1 ','20190214')
    insert into @parent_course_dates values('1 ','20190215')
    insert into @parent_course_dates values('1 ','20190218')
    insert into @parent_course_dates values('1 ','20190219')
    insert into @parent_course_dates values('1 ','20190220')
    insert into @parent_course_dates values('1 ','20190221')
    insert into @parent_course_dates values('1 ','20190222')
    insert into @parent_course_dates values('1 ','20190225')
    insert into @parent_course_dates values('1 ','20190226')
    insert into @parent_course_dates values('1 ','20190227')
    insert into @parent_course_dates values('1 ','20190228')
    insert into @parent_course_dates values('1 ','20190301')
    insert into @parent_course_dates values('1 ','20190304')
    insert into @parent_course_dates values('1 ','20190305')
    insert into @parent_course_dates values('1 ','20190306')
    insert into @parent_course_dates values('1 ','20190307')
    insert into @parent_course_dates values('1 ','20190308')
    insert into @parent_course_dates values('1 ','20190311')
    insert into @parent_course_dates values('1 ','20190312')
    insert into @parent_course_dates values('1 ','20190313')
    insert into @parent_course_dates values('1 ','20190314')
    insert into @parent_course_dates values('1 ','20190315')
    insert into @parent_course_dates values('1 ','20190318')
    insert into @parent_course_dates values('1 ','20190319')
    insert into @parent_course_dates values('1 ','20190320')
    insert into @parent_course_dates values('1 ','20190321')
    insert into @parent_course_dates values('1 ','20190322')
    insert into @parent_course_dates values('1 ','20190325')
    insert into @parent_course_dates values('1 ','20190326')
    insert into @parent_course_dates values('1 ','20190327')
    insert into @parent_course_dates values('1 ','20190328')
    insert into @parent_course_dates values('1 ','20190329')
    insert into @parent_course_dates values('1 ','20190401')
    insert into @parent_course_dates values('1 ','20190402')
    insert into @parent_course_dates values('1 ','20190403')
    insert into @parent_course_dates values('1 ','20190404')
    insert into @parent_course_dates values('1 ','20190405')
    insert into @parent_course_dates values('1 ','20190408')
    insert into @parent_course_dates values('1 ','20190409')
    insert into @parent_course_dates values('1 ','20190410')
    insert into @parent_course_dates values('1 ','20190411')
    insert into @parent_course_dates values('1 ','20190412')
    insert into @parent_course_dates values('1 ','20190415')
    insert into @parent_course_dates values('1 ','20190416')
    insert into @parent_course_dates values('1 ','20190417')
    insert into @parent_course_dates values('1 ','20190418')
    insert into @parent_course_dates values('1 ','20190423')
    insert into @parent_course_dates values('1 ','20190424')
    insert into @parent_course_dates values('1 ','20190425')
    insert into @parent_course_dates values('1 ','20190426')
    insert into @parent_course_dates values('1 ','20190429')
    insert into @parent_course_dates values('1 ','20190430')
    insert into @parent_course_dates values('1 ','20191231')
    insert into @parent_course_dates values('35','20190102')
    insert into @parent_course_dates values('35','20190103')
    insert into @parent_course_dates values('35','20190104')
    insert into @parent_course_dates values('35','20190107')
    insert into @parent_course_dates values('35','20190108')
    insert into @parent_course_dates values('35','20190109')
    insert into @parent_course_dates values('35','20190110')
    insert into @parent_course_dates values('35','20190111')
    insert into @parent_course_dates values('35','20190114')
    insert into @parent_course_dates values('35','20190115')
    insert into @parent_course_dates values('35','20190116')
    insert into @parent_course_dates values('35','20190117')
    insert into @parent_course_dates values('35','20190118')
    insert into @parent_course_dates values('35','20190121')
    insert into @parent_course_dates values('35','20190122')
    insert into @parent_course_dates values('35','20190123')
    insert into @parent_course_dates values('35','20190124')
    insert into @parent_course_dates values('35','20190125')
    insert into @parent_course_dates values('35','20190128')
    insert into @parent_course_dates values('35','20190129')
    insert into @parent_course_dates values('35','20190130')
    insert into @parent_course_dates values('35','20190131')
    insert into @parent_course_dates values('35','20190201')
    insert into @parent_course_dates values('35','20190204')
    insert into @parent_course_dates values('35','20190205')
    insert into @parent_course_dates values('35','20190206')
    insert into @parent_course_dates values('35','20190207')
    insert into @parent_course_dates values('35','20190208')
    insert into @parent_course_dates values('35','20190211')
    insert into @parent_course_dates values('35','20190212')
    insert into @parent_course_dates values('35','20190213')
    insert into @parent_course_dates values('35','20190214')
    insert into @parent_course_dates values('35','20190215')
    insert into @parent_course_dates values('35','20190218')
    insert into @parent_course_dates values('35','20190219')
    insert into @parent_course_dates values('35','20190220')
    insert into @parent_course_dates values('35','20190221')
    insert into @parent_course_dates values('35','20190222')
    insert into @parent_course_dates values('35','20190225')
    insert into @parent_course_dates values('35','20190226')
    insert into @parent_course_dates values('35','20190227')
    insert into @parent_course_dates values('35','20190228')
    insert into @parent_course_dates values('35','20190301')
    insert into @parent_course_dates values('35','20190304')
    insert into @parent_course_dates values('35','20190305')
    insert into @parent_course_dates values('35','20190306')
    insert into @parent_course_dates values('35','20190307')
    insert into @parent_course_dates values('35','20190308')
    insert into @parent_course_dates values('35','20190311')
    insert into @parent_course_dates values('35','20190312')
    insert into @parent_course_dates values('35','20190313')
    insert into @parent_course_dates values('35','20190314')
    insert into @parent_course_dates values('35','20190315')
    insert into @parent_course_dates values('35','20190318')
    insert into @parent_course_dates values('35','20190319')
    insert into @parent_course_dates values('35','20190320')
    insert into @parent_course_dates values('35','20190321')
    insert into @parent_course_dates values('35','20190322')
    insert into @parent_course_dates values('35','20190325')
    insert into @parent_course_dates values('35','20190326')
    insert into @parent_course_dates values('35','20190327')
    insert into @parent_course_dates values('35','20190328')
    insert into @parent_course_dates values('35','20190329')
    insert into @parent_course_dates values('35','20190401')
    insert into @parent_course_dates values('35','20190402')
    insert into @parent_course_dates values('35','20190403')
    insert into @parent_course_dates values('35','20190404')
    insert into @parent_course_dates values('35','20190405')
    insert into @parent_course_dates values('35','20190408')
    insert into @parent_course_dates values('35','20190409')
    insert into @parent_course_dates values('35','20190410')
    insert into @parent_course_dates values('35','20190411')
    insert into @parent_course_dates values('35','20190412')
    insert into @parent_course_dates values('35','20190415')
    insert into @parent_course_dates values('35','20190416')
    insert into @parent_course_dates values('35','20190417')
    insert into @parent_course_dates values('35','20190418')
    insert into @parent_course_dates values('35','20190422')
    insert into @parent_course_dates values('35','20190423')
    insert into @parent_course_dates values('35','20190424')
    insert into @parent_course_dates values('35','20190425')
    insert into @parent_course_dates values('35','20190426')
    insert into @parent_course_dates values('35','20190429')
    insert into @parent_course_dates values('35','20190430')

    insert into @alldates values ('20190101','Tuesday')
    insert into @alldates values ('20190102','Wednesday')
    insert into @alldates values ('20190103','Thursday')
    insert into @alldates values ('20190104','Friday')
    insert into @alldates values ('20190105','Saturday')
    insert into @alldates values ('20190106','Sunday')
    insert into @alldates values ('20190107','Monday')
    insert into @alldates values ('20190108','Tuesday')
    insert into @alldates values ('20190109','Wednesday')
    insert into @alldates values ('20190110','Thursday')
    insert into @alldates values ('20190111','Friday')
    insert into @alldates values ('20190112','Saturday')
    insert into @alldates values ('20190113','Sunday')
    insert into @alldates values ('20190114','Monday')
    insert into @alldates values ('20190115','Tuesday')
    insert into @alldates values ('20190116','Wednesday')
    insert into @alldates values ('20190117','Thursday')
    insert into @alldates values ('20190118','Friday')
    insert into @alldates values ('20190119','Saturday')
    insert into @alldates values ('20190120','Sunday')
    insert into @alldates values ('20190121','Monday')
    insert into @alldates values ('20190122','Tuesday')
    insert into @alldates values ('20190123','Wednesday')
    insert into @alldates values ('20190124','Thursday')
    insert into @alldates values ('20190125','Friday')
    insert into @alldates values ('20190126','Saturday')
    insert into @alldates values ('20190127','Sunday')
    insert into @alldates values ('20190128','Monday')
    insert into @alldates values ('20190129','Tuesday')
    insert into @alldates values ('20190130','Wednesday')
    insert into @alldates values ('20190131','Thursday')
    insert into @alldates values ('20190201','Friday')
    insert into @alldates values ('20190202','Saturday')
    insert into @alldates values ('20190203','Sunday')
    insert into @alldates values ('20190204','Monday')
    insert into @alldates values ('20190205','Tuesday')
    insert into @alldates values ('20190206','Wednesday')
    insert into @alldates values ('20190207','Thursday')
    insert into @alldates values ('20190208','Friday')
    insert into @alldates values ('20190209','Saturday')
    insert into @alldates values ('20190210','Sunday')
    insert into @alldates values ('20190211','Monday')
    insert into @alldates values ('20190212','Tuesday')
    insert into @alldates values ('20190213','Wednesday')
    insert into @alldates values ('20190214','Thursday')
    insert into @alldates values ('20190215','Friday')
    insert into @alldates values ('20190216','Saturday')
    insert into @alldates values ('20190217','Sunday')
    insert into @alldates values ('20190218','Monday')
    insert into @alldates values ('20190219','Tuesday')
    insert into @alldates values ('20190220','Wednesday')
    insert into @alldates values ('20190221','Thursday')
    insert into @alldates values ('20190222','Friday')
    insert into @alldates values ('20190223','Saturday')
    insert into @alldates values ('20190224','Sunday')
    insert into @alldates values ('20190225','Monday')
    insert into @alldates values ('20190226','Tuesday')
    insert into @alldates values ('20190227','Wednesday')
    insert into @alldates values ('20190228','Thursday')
    insert into @alldates values ('20190301','Friday')
    insert into @alldates values ('20190302','Saturday')
    insert into @alldates values ('20190303','Sunday')
    insert into @alldates values ('20190304','Monday')
    insert into @alldates values ('20190305','Tuesday')
    insert into @alldates values ('20190306','Wednesday')
    insert into @alldates values ('20190307','Thursday')
    insert into @alldates values ('20190308','Friday')
    insert into @alldates values ('20190309','Saturday')
    insert into @alldates values ('20190310','Sunday')
    insert into @alldates values ('20190311','Monday')
    insert into @alldates values ('20190312','Tuesday')
    insert into @alldates values ('20190313','Wednesday')
    insert into @alldates values ('20190314','Thursday')
    insert into @alldates values ('20190315','Friday')
    insert into @alldates values ('20190316','Saturday')
    insert into @alldates values ('20190317','Sunday')
    insert into @alldates values ('20190318','Monday')
    insert into @alldates values ('20190319','Tuesday')
    insert into @alldates values ('20190320','Wednesday')
    insert into @alldates values ('20190321','Thursday')
    insert into @alldates values ('20190322','Friday')
    insert into @alldates values ('20190323','Saturday')
    insert into @alldates values ('20190324','Sunday')
    insert into @alldates values ('20190325','Monday')
    insert into @alldates values ('20190326','Tuesday')
    insert into @alldates values ('20190327','Wednesday')
    insert into @alldates values ('20190328','Thursday')
    insert into @alldates values ('20190329','Friday')
    insert into @alldates values ('20190330','Saturday')
    insert into @alldates values ('20190331','Sunday')
    insert into @alldates values ('20190401','Monday')
    insert into @alldates values ('20190402','Tuesday')
    insert into @alldates values ('20190403','Wednesday')
    insert into @alldates values ('20190404','Thursday')
    insert into @alldates values ('20190405','Friday')
    insert into @alldates values ('20190406','Saturday')
    insert into @alldates values ('20190407','Sunday')
    insert into @alldates values ('20190408','Monday')
    insert into @alldates values ('20190409','Tuesday')
    insert into @alldates values ('20190410','Wednesday')
    insert into @alldates values ('20190411','Thursday')
    insert into @alldates values ('20190412','Friday')
    insert into @alldates values ('20190413','Saturday')
    insert into @alldates values ('20190414','Sunday')
    insert into @alldates values ('20190415','Monday')
    insert into @alldates values ('20190416','Tuesday')
    insert into @alldates values ('20190417','Wednesday')
    insert into @alldates values ('20190418','Thursday')
    insert into @alldates values ('20190419','Friday')
    insert into @alldates values ('20190420','Saturday')
    insert into @alldates values ('20190421','Sunday')
    insert into @alldates values ('20190422','Monday')
    insert into @alldates values ('20190423','Tuesday')
    insert into @alldates values ('20190424','Wednesday')
    insert into @alldates values ('20190425','Thursday')
    insert into @alldates values ('20190426','Friday')
    insert into @alldates values ('20190427','Saturday')
    insert into @alldates values ('20190428','Sunday')
    insert into @alldates values ('20190429','Monday')
    insert into @alldates values ('20190430','Tuesday')

1 个答案:

答案 0 :(得分:0)

以下是使用相同逻辑the one of 19/04/2019 I posted

的解决方案

请在@tabholiday中插入您所在国家/地区的假期日期

declare @tabholiday as table(holiday_date date)

declare @tab_monday as table (m int,date_found date)
declare @tab_monday2 as table (m int,date_found date)
declare @tab_tuesday as table (m int,date_found date)
declare @tab_wednesday as table (m int,date_found date)
declare @tab_friday as table (m int,date_found date)
declare @tab_saturday as table (m int,date_found date)
declare @tab_saturday2 as table (m int,date_found date)

insert into @tabholiday values('2019/01/07'),('2019/01/11'),('2019/03/20'),('2019/04/09'),('2019/05/01'),('2019/07/25'),('2019/08/13'),('2019/10/15')
declare @calendar as table(wd int,fulldate date,dayname varchar(20),m int,weekday_rank_month int,holiday int)

--Script by Kemal AL GAZZAH
--26/04/2019

set dateformat dmy

--Filling the @Calendar Table------------

;WITH cte as (SELECT cast('01/01/2019' as date) as d 
UNION ALL SELECT dateadd(day,1,d)  AS d FROM cte WHERE year(dateadd(day,1,d))=2019 ) 
insert into @calendar SELECT cast(replace(d,'-','') as int) wd,d fulldate,
case datepart(w,d)
when 1 then 'Sunday'
when 2 then 'Monday'
when 3 then 'Tuesday'
when 4 then 'Wednesday'
when 5 then 'Thursday'
when 6 then 'Friday'
when 7 then 'Saturday'
end

 [dayname] ,month(d) [M]
 ,row_number() over (partition by datepart(w,d),month(d) order by d) weekday_rank_month,case isnull(t2.holiday_date,'') when '' then 0 else 1 end [holiday]

 FROM cte t1 left outer join @tabholiday t2 on t1.d=t2.holiday_date

  order by d 
 OPTION (MAXRECURSION 366);




 --1 )Monday after third thursday of month 
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='monday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=3 and t1.dayname='thursday')
  insert into @tab_monday 
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d2
  end [Monday after third thursday of month] from cte

 --2)wednesday before third thursday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='wednesday' and t2.fulldate < t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=3 and t1.dayname='thursday')
  insert into @tab_wednesday 
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d2
  end [wednesday before third thursday of month in active_in_months] from cte

  --3)Tuesday after second thursday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='Tuesday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=2 and t1.dayname='thursday')
  insert into @tab_Tuesday 
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d2
  end [Tuesday after second thursday of month in active_in_months] from cte

 --4)monday after third friday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='monday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=3 and t1.dayname='friday')
  insert into @tab_Monday2 
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d2
  end [monday after third friday of month in active_in_months] from cte


 --5)Friday after second monday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='Friday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=2 and t1.dayname='monday')
  insert into @tab_Friday
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d2
  end [Friday after second monday of month in active_in_months] from cte


  --6)saturday after second friday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='Saturday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=2 and t1.dayname='Friday')
  insert into @tab_saturday
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d1 --d2 (no effect on holiday)
  end [saturday after second friday of month in active_in_months] from cte

  --7)saturday after second monday of month in active_in_months
  ;
  with cte as
  (
  select t1.m[Month],t2.fulldate d1,t2.holiday,t3.fulldate d2  from @calendar t1 
  outer apply(select top 1 * from  @calendar t2 where t2.dayname='Saturday' and t2.fulldate > t1.fulldate order by fulldate) t2
  outer apply (select top 1 * from @calendar t3 where fulldate > t2.fulldate and holiday=0 and month(fulldate)=t1.m order by fulldate ) t3
  where t1.weekday_rank_month=2 and t1.dayname='monday')
  insert into @tab_saturday2
  select 
  [Month],
  case 
  when holiday=0 then d1 
  else d1 --d2 (no effect on holiday)
  end [saturday after second friday of month in active_in_months] from cte


   --8)-Jointure Between 7 Tables





 select t1.m [Month],
 t1.date_found [Monday1],
 t2.date_found [Monday2],
 t3.date_found [Tuesday],
 t4.date_found [Wednesady],
 t5.date_found [Friday],
 t6.date_found [Saturday1],
 t7.date_found [Saturday2]

 from  @tab_monday t1 
 inner join @tab_monday2 t2 on t1.m=t2.m
 inner join @tab_tuesday t3 on t1.m=t3.m
 inner join @tab_wednesday t4 on t1.m=t4.m
 inner join @tab_friday t5 on t1.m=t5.m
 inner join @tab_saturday t6 on t1.m=t6.m
 inner join @tab_saturday2 t7 on t1.m=t7.m