-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarEntryTransformation.sql
58 lines (53 loc) · 1.77 KB
/
CalendarEntryTransformation.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
48
49
50
51
52
53
54
55
56
57
58
SELECT Date
, Duration
, DurationSeconds
, Note
INTO #ReqEntry
FROM CalendarEntry
INNER JOIN CalendarEntryType
ON CalendarEntryType.Id = CalendarEntry.CalendarEntryTypeId
AND CalendarEntryType.Id = 1 -- WorkTime
ORDER BY Date
, CalendarEntryType.Id
SELECT Date
, Duration
, DurationSeconds
, Name
, Note
INTO #WorkEntry
FROM CalendarEntry
INNER JOIN CalendarEntryType
ON CalendarEntryType.Id = CalendarEntry.CalendarEntryTypeId
AND CalendarEntryType.Id IN (2, 3, 6) -- Office, Mobile, TimeCompensation
ORDER BY Date
, CalendarEntryType.Id
SELECT Date
, Duration
, DurationSeconds
, Name
, Note
INTO #LeavEntry
FROM CalendarEntry
INNER JOIN CalendarEntryType
ON CalendarEntryType.Id = CalendarEntry.CalendarEntryTypeId
AND CalendarEntryType.Id IN (4, 5, 7) -- Holiday, Vacation, Ill
ORDER BY Date
, CalendarEntryType.Id
--INSERT [WorkTime] ([WorkTimeTypeId], [Date], [ExpectedSeconds], [ActualSeconds], [Note])
SELECT CASE #WorkEntry.Name WHEN 'Office' THEN 1 WHEN 'Mobile' THEN 2 WHEN 'TimeCompensation' THEN (CASE LEFT(#ReqEntry.Note, CHARINDEX(':', #ReqEntry.Note) - 1) WHEN 'Büro' THEN 1 WHEN 'Mobil' THEN 2 END) END
, #WorkEntry.Date
, ISNULL(#ReqEntry.DurationSeconds, 0)
, CASE #WorkEntry.Name WHEN 'TimeCompensation' THEN 0 ELSE #WorkEntry.DurationSeconds END
, CASE #WorkEntry.Name WHEN 'TimeCompensation' THEN 'Zeitausgleich' ELSE #WorkEntry.Note END
FROM #WorkEntry
LEFT JOIN #ReqEntry
ON #ReqEntry.Date = #WorkEntry.Date
ORDER BY #WorkEntry.Date
--INSERT [Absence] ([AbsenceTypeId], [Date], [DurationSeconds], [Note])
SELECT CASE Name WHEN 'Holiday' THEN 1 WHEN 'Vacation' THEN 2 WHEN 'Ill' THEN 3 END
, Date
, DurationSeconds
, Note
FROM #LeavEntry
ORDER BY Date
DROP TABLE #LeavEntry, #ReqEntry, #WorkEntry