The database EmployeesDB contains the information of the employees of an import and export company - NSC Information Technology - Question 2 - 2020 - Paper 1
Question 2
The database EmployeesDB contains the information of the employees of an import and export company. The database contains two tables called tblEmployees and tblHourL... show full transcript
Worked Solution & Example Answer:The database EmployeesDB contains the information of the employees of an import and export company - NSC Information Technology - Question 2 - 2020 - Paper 1
Step 1
Button (2.1.1 - List of employees)
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display all the information of employees from the tblEmployees table, we use the following SQL statement:
SELECT * FROM tblEmployees;
Step 2
Button (2.1.2 - Engineers)
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To retrieve the EmployeeID, LastName, and FirstName fields of employees whose job title contains the word 'Engineer', the SQL statement is:
SELECT EmployeeID, LastName, FirstName FROM tblEmployees WHERE JobTitle LIKE '%Engineer%';
Step 3
Button (2.1.3 - Job titles)
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display a list of all unique job titles at the company, the SQL statement is:
SELECT DISTINCT JobTitle FROM tblEmployees;
Step 4
Button (2.1.4 - Remove records)
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To remove all records in the tblHourLogs table where the HoursWorked is 99, the SQL statement used is:
DELETE FROM tblHourLogs WHERE HoursWorked = 99;
Step 5
Button (2.1.5 - Overtime)
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To calculate the overtime payments for employees, the SQL statement to execute is:
SELECT LastName, FORMAT(SUM((HoursWorked - 8) * HourlyWage * 2), 'Currency') AS OvertimeAmt FROM tblEmployees e, tblHourLogs h WHERE e.EmployeeID = h.EmployeeID AND HoursWorked > 8 GROUP BY LastName;
Step 6
Button (2.2.1 - Employees with first aid)
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To display the EmployeeID, LastName, and JobTitle of all employees who have completed first aid training, the Delphi code should loop through the tblEmployees table and check the FirstAidTraining field. The implementation can include a counter to track the number of employees:
// Display column headings
Memo1.Lines.Add('EmployeeID | LastName | JobTitle');
// Initialize counter
docount := 0;
while not tblEmployees.Eof do begin
if tblEmployees.FieldByName('FirstAidTraining').AsBoolean then begin
Memo1.Lines.Add(Format('%s | %s | %s', [tblEmployees.FieldByName('EmployeeID').AsString, tblEmployees.FieldByName('LastName').AsString, tblEmployees.FieldByName('JobTitle').AsString]));
inc(docount);
end;
tblEmployees.Next;
end;
Memo1.Lines.Add('Total number of employees who completed first aid training: ' + IntToStr(docount));
Step 7
Button (2.2.2 - Add new employee)
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To add a new record in the tblEmployees table, the following Delphi code can be used:
Sign up now to view full answer, or log in if you already have an account!
Answer
To update the number of hours worked in the tblHourLogs table, you would use the following Delphi code:
// Assuming selected LogID from the grid is already known
selectedLogID := 174;
if tblHourLogs.Locate('LogID', selectedLogID, []) then begin
tblHourLogs.Edit;
tblHourLogs.FieldByName('HoursWorked').AsInteger := newHoursWorked; // newHoursWorked is user input
tblHourLogs.Post;
end;