| 1 | create or replace function CertificationExpiry(
|
|---|
| 2 | DaysUntil int
|
|---|
| 3 | ) returns table (
|
|---|
| 4 | EmployeeId int,
|
|---|
| 5 | Name varchar(50),
|
|---|
| 6 | Surname varchar(50),
|
|---|
| 7 | Active bool,
|
|---|
| 8 | CertificationId int,
|
|---|
| 9 | CertificationType text,
|
|---|
| 10 | AirplaneModel varchar(100),
|
|---|
| 11 | ExpirationDate date,
|
|---|
| 12 | DaysUntilExpiration int,
|
|---|
| 13 | IsExpired bool
|
|---|
| 14 | ) as $$
|
|---|
| 15 | begin
|
|---|
| 16 | if DaysUntil < 0 then
|
|---|
| 17 | raise exception 'Invalid number of days!';
|
|---|
| 18 | end if;
|
|---|
| 19 |
|
|---|
| 20 | return query
|
|---|
| 21 | select s.EmployeeId, s.name, s.Surname, s.Active,
|
|---|
| 22 | s.CertificationId, s.CertificationType, s.AirplaneModel, s.ExpirationDate,
|
|---|
| 23 | s.DaysUntilExpiration, s.IsExpired
|
|---|
| 24 | from certificationexpirystatus as s
|
|---|
| 25 | where s.DaysUntilExpiration <= DaysUntil and s.active = true
|
|---|
| 26 | order by s.DaysUntilExpiration, s.EmployeeId;
|
|---|
| 27 | end;
|
|---|
| 28 | $$ language plpgsql;
|
|---|