select EmpID,
Day1_假期名称=(select top 1 名称
from 假期表
where charindex(cast(id as varchar),Day1_A+Day1_P)>0 ),
Day1_A=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OnDuty2 from 班次表 when Id=Day1_P)
when 2 then (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
else (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
end),
Day1_P=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OffDuty2 from 班次表 when Id=Day1_A)
when 2 then (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
else (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
end),
--...
from 排班表
Day1_假期名称=(select top 1 名称
from 假期表
where charindex(cast(id as varchar),Day1_A+Day1_P)>0 ),
Day1_A=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OnDuty2 from 班次表 when Id=Day1_P)
when 2 then (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
else (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
end),
Day1_P=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OffDuty2 from 班次表 when Id=Day1_A)
when 2 then (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
else (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
end),
--...
from 排班表
Day1_假期名称=(select top 1 名称
from 假期表
where charindex(cast(id as varchar),Day1_A+Day1_P)>0 ),
Day1_A=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OnDuty2 from 班次表 when Id=Day1_P)
when 2 then (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
else (select top 1 OnDuty1 from 班次表 when Id=Day1_P)
end),
Day1_P=(case patindex('%[0-9]%',Day1_A+Day1_P)
when 1 then (select top 1 OffDuty2 from 班次表 when Id=Day1_A)
when 2 then (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
else (select top 1 OffDuty1 from 班次表 when Id=Day1_A)
end),
--...
from 排班表
用函数处理班次及假期的处理,作为返回值
在
SELECT EMPID,F(DAY1_A),F(DAY1_P),
F(DAY2_A),F(DAY2_P),
................
FROM 排班表