You can do this using DATEPART and CTE. Here's the relevant part:
;with wkNum as ( SELECT weekDay, EmployeeName, deptID, (DATEPART(wk, weekDay) / 2) % 2 as period FROM EmployeeOnCall ) UPDATE wkNum SET employeename = CASE WHEN wkNum.period = 0 THEN 'Jones, Jim' ELSE 'Penton, Andy' END
The idea is to determine what week of the year is, divide it by 2, and then modulo by the number of employees you deal with. And here is the test script:
DECLARE @test TABLE (weekDay datetime, employeename varchar(50), deptID int); DEClARE @startdate datetime = '2016-02-16'; declare @enddate datetime = '2016-12-31'; ;with N0 as (SELECT 1 as n UNION ALL SELECT 1) ,N1 as (SELECT 1 as n FROM N0 t1, N0 t2) ,N2 as (SELECT 1 as n FROM N1 t1, N1 t2) ,N3 as (SELECT 1 as n FROM N2 t1, N2 t2) ,N4 as (SELECT 1 as n FROM N3 t1, N3 t2) ,N5 as (SELECT 1 as n FROM N4 t1, N4 t2) ,N6 as (SELECT 1 as n FROM N5 t1, N5 t2) ,nums as (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) as num FROM N6) INSERT @test (weekDay, deptID) SELECT DATEADD(day,num-1,@startdate) as thedate, 25 FROM nums WHERE num <= DATEDIFF(day,@startdate,@enddate) + 1 ;with wkNum as ( SELECT weekDay, EmployeeName, deptID, (DATEPART(wk, weekDay) / 2) % 2 as period FROM @test ) UPDATE wkNum SET employeename = CASE WHEN wkNum.period = 0 THEN 'Jones, Jim' ELSE 'Penton, Andy' END SELECT * FROM @test
If you have a staff table to pull from it, it can be expanded as follows:
DECLARE @emps TABLE (Name varchar(100)); INSERT @emps VALUES ('Dan'), ('Joe'), ('Asdf') UPDATE eoc SET employeename = emp.Name FROM EmployeeOnCall eoc INNER JOIN (SELECT ROW_NUMBER() OVER(ORDER BY Name) rn, Name FROM @emps) emp ON ((DATEPART(wk, weekDay) / 2) % (SELECT COUNT(*) FROM @emps)) + 1 = emp.rn