Okay I've been fiddling around a little with the CMIS data (they should really offer an API for access).
My problems are that we have a two week timetable. The data itself is modeled quite strangely as it not uses database fileds like weekID or periodid.
Instead our week is 14 days long starting on Sunday and the periods are entered as fixed values in a string (d'oh).
Luckily the database is poorly designed so a lot of information is flying around (now I finally know why the data consistency in CMIS is so bad). This is what I've come up with so far. You put in a start-date and an end-date and you get a list of busy periods.
Of course this is highly specific to our school but I guess you should be able to modify.
-- In date range
-- Out busy periods
declare @startDate as datetime
declare @endDate as datetime
declare @setID as char(10)
set @startdate = '20091101'
set @enddate = '20091130'
set @setID= '2009/2010'
select cm.mapdate,tt.lecturerid, tg.groupcode, 'Lesson' =
CASE
WHEN tt.startTime = '08:45' THEN '0'
WHEN tt.startTime = '09:05' THEN '1'
WHEN tt.startTime = '09:15' THEN '1'
WHEN tt.startTime = '11:05' THEN '2'
WHEN tt.startTime = '13:25' THEN '3'
END,
tt.starttime, tt.roomid
from ccalmaps cm
inner join timetable tt on
tt.setid = cm.setid and tt.weekday=cm.dayposn
inner join teachinggroups tg on
tg.setid=cm.setid and tg.groupid=tt.groupid
where cm.setid=@setID
and cm.mapdate <= @endDate
and cm.mapdate >= @startDate
and tt.roomid is not null
-- and tt.roomid=@room
order by roomid,mapdate, lesson
.... now how time to put this into the mrbs_entry table ...