-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateLastFU.sql
46 lines (46 loc) · 4.32 KB
/
DateLastFU.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
ISNULL({Personal\P DOD},
IF
(
CASE
WHEN isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111))
WHEN isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
AND isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111))
WHEN isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111))
WHEN isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111))
END
) = convert(datetime,'1900-01-02',111)
THEN NULL
ELSE
(
CASE
WHEN isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Consent Date},convert(datetime,'1900-01-02',111))
WHEN isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
AND isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-02',111))
WHEN isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Date Last Seen},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-02',111))
WHEN isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Tracing Received Date},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Query\Front Sheet\Date Blood Received},convert(datetime,'1900-01-01',111))
AND isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111)) >= isnull({Audit\Consent Date},convert(datetime,'1900-01-01',111))
THEN isnull({Audit\Date Last Seen},convert(datetime,'1900-01-02',111))
END
)
ENDIF
)