To find the total count of tasks that are updated and are not associated with a project, you should use a query that captures both TaskId and ProjectId to filter correctly. The update and output logic must ensure that null StartTimes are targeted, updated, and the corresponding ProjectId is captured to count those with null ProjectIds. So, the correct set of Transact-SQL statements you should run is: DECLARE @startedTasks TABLE(TaskId int, ProjectId int) UPDATE Task SET StartTime = GETDATE() OUTPUT deleted.TaskId, deleted.ProjectId INTO @startedTasks WHERE StartTime is NULL SELECT COUNT(*) FROM @startedTasks WHERE ProjectId IS NULL This query first declares a table variable to capture TaskId and ProjectId of the updated rows. In the update statement, it sets the StartTime to the current date and time for tasks with a null StartTime. The OUTPUT clause captures the TaskId and ProjectId of each updated row into the @startedTasks table. Finally, a SELECT statement counts the rows in @startedTasks where ProjectId is null, effectively giving the count of tasks updated that are not associated with a project.