SELECT DISTINCT
Users. Su01 as job number,
Users. SU02 as name,
The substring (users. Su03, 29, 6) as department,
The MONTH (dateadd (MONTH, 1, getdate ())) in the as,
Day (dateadd (ms - 3, dateadd (mm, DATEDIFF (m, 0, getdate ()) + 1, 0))) as' days month/day,
Isnull (sum (a. d. ays), 0) as annual leave,
Isnull (sum (b.d ays), 0) as paid sick leave,
Isnull (sum (c.d ays), 0) as wedding leave,
Isnull (sum (d.d ays), 0) as funeral leave,
Isnull (sum (e.d ays), 0) as prenatal false,
Isnull (sum (f.d ays), 0) as paternity leave,
Isnull (sum (g.d ays), 0) as home leave,
Isnull (sum (h.d ays), 0) as cease,
Isnull (sum (i.d ays), 0) as inductrial injury,
Isnull (sum (j. ays), 0) as maternity leave,
Isnull (sum (k.d ays), 0) as sick leave,
Isnull (sum (l.d ays), 0) as personal leave,
Isnull (sum (n.d ays), 0) as absenteeism,
Isnull (sum (m. ays), 0) as unpaid leave,
30 - isnull (a. d. ays, 0) - isnull (b.d ays, 0) - isnull (c.d ays, 0) - isnull (d.d ays, 0) - isnull (e.d ays, 0) - isnull (f.d ays, 0) - isnull (g.d ays, 0) - isnull (h.d ays, 0) - isnull (i.d ays, 0) - isnull (j. ays, 0) - isnull (k.d ays, 0) - isnull (l.d ays, 0) - isnull (n.d ays, 0) - isnull (m. ays, 0) as the actual attendance,
30 - isnull (a. d. ays, 0) - isnull (b.d ays, 0) - isnull (c.d ays, 0) - isnull (d.d ays, 0) - isnull (e.d ays, 0) - isnull (f.d ays, 0) - isnull (g.d ays, 0) - isnull (h.d ays, 0) - isnull (i.d ays, 0) - isnull (j. ays, 0) - isnull (k.d ays, 0) - isnull (l.d ays, 0) - isnull (n.d ays, 0) - isnull (m. ays, 0) + isnull (a. d. ays, 0) + isnull (b.d ays, 0) + isnull (e.d ays, 0) + isnull (g.d ays, 0) + isnull (h.d ays, 0) + isnull (d.d ays, 0) + isnull (i.d ays, 0) + isnull (f.d ays, 0) + isnull (c.d ays, 0) as paid for days
The FROM FE_BASE5.. SYS_USERS
The join
(SELECT
Su01,
Su02,
Su03
The FROM FE_BASE5.. SYS_USERS)
The users on the users. Su01=FE_BASE5.. SYS_USERS. Su01
Left the join
(SELECT su02 name, a1. Fn16 days FROM FE_BASE5. J. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG>='annual leave' '0' and fn07 and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
A1 on a1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
A. on a.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, b1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='paid sick leave and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
B1 on b1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
B on b.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, c1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='wedding' and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
C1 on c1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
C on c.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, d1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='funeral leave and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
D1 on d1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
D on d.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, e1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='prenatal false and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
E1 on e1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
E on e.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, f1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='paternity leave and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
F1 on f1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
F on the cash-strapped ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, g1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG>='home leave' '0' and fn07 and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
G1 on g1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
G on g.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, h1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG>='busy' '0' and fn07 and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
H1 on h1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
H on h.n ame=FE_BASE5.. SYS_USERS. Su02
Left the join
(SELECT su02 name, i1. Fn16 days FROM FE_BASE5.. SYS_USERS
Left the join
(SELECT * FROM FE_APP5.. FT_1_8D06B1699979D8FC5C01
WHERE SPFLAG> '0' and fn07='inductrial injury and fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
I1 on i1. Fn04=FE_BASE5.. SYS_USERS. Su00
Where fn05 & gt;='2020-12-01' and fn10 & lt;='2020-12-31')
I on i.n ame=FE_BASE5.. nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull