CRUD Statements  «Prev  Next»

UPDATE Using a Joined Table — Exercise

Create an UPDATE statement using values from another table

Objective:Practice creating an UPDATE statement using values from another table.

Exercise scoring

This is a 20-point self-assessment. Compare your SQL with the model answer and rubric after submitting. The website does not execute SQL or automatically grade your response.

Instructions

Practice environment: Write SQL for the sample tables in the dbo schema. Submitting displays your text and a model answer; it does not run database commands. If you test independently, use a disposable practice database.

Assume Tasks.TaskID is a primary key, Timesheets.TaskID references it, WeekEndingDate has the date type, and Hours is numeric. The five displayed timesheet rows form the complete sample. For the UPDATE exercise, the listed employee/task/date combination identifies one row.

Using the course project as an example, the Timesheets table looks like this:
EmployeeID ClientID TaskID WeekEndingDate Hours
1171012026-06-0130
1171022026-06-0850
231012026-06-1540
3321032026-06-0145
3321032026-06-0835

The Tasks table looks like this:

TaskID

Description

Chargeable

101 Vacation 0
102 General 1
103 Programming 1

The company realized that for the week ending 2026-06-01, employee number 1 recorded 30 vacation hours, but he should have charged 40 hours. Assuming that you do not know the TaskID for Vacation, Construct an UPDATE statement that uses both tables to update the Hours column in the Timesheets table to the appropriate value.
Self-assessment rubric
PointsCriterion
4Update Timesheets.Hours to 40.
4Join Timesheets to Tasks using TaskID.
4Find the task using Description = 'Vacation', without hard-coding TaskID.
4Restrict the update to EmployeeID = 1.
4Restrict the update to the date 2026-06-01 using an unambiguous date expression.

Submitting the exercise

Type or paste your Transact-SQL statement into the text box below, then click Submit to submit them and view a results page.