-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateDailyReliefsEmailLog.sql
49 lines (38 loc) · 1.22 KB
/
UpdateDailyReliefsEmailLog.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
USE [CanvasAdmin]
GO
/****** Object: StoredProcedure [dbo].[spiUpdateDailyReliefsEmailLog] Script Date: 30/11/2020 10:23:18 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[spiUpdateDailyReliefsEmailLog]
as begin
/* We want to send an email to each teacher containing information about every class which
they are relieving for a particular day. We don't want to send an email about a particular class more than
once. So, if the email log currently contains an entry for a teacher + class + day, we do not want
to re-insert it. */
insert into dbo.DailyReliefsEmailLog (
ReliefDate,
ClassCode,
ReliefTeacherName,
ReliefTeacherId,
ReliefTeacherEmail)
select distinct
cast(GETDATE() as Date),
ClassCode,
ReliefTeacherName,
ReliefTeacherId,
ReliefTeacherEmail
from DailyReliefs
where DATEDIFF(day, datemodified, getdate()) = 0
except
select distinct
cast(GETDATE() as Date),
ClassCode,
ReliefTeacherName,
ReliefTeacherId,
ReliefTeacherEmail
from DailyReliefsEmailLog
where DATEDIFF(day, ReliefDate, getdate()) = 0
end
GO