UPDATE tm.Task
SET StartDate = CASE
WHEN (
SELECT min(PickingTime)
FROM tm.TaskItem
WHERE tm.TaskItem.TaskId = tm.Task.taskId
) IS NOT NULL
THEN (
SELECT min(PickingTime)
FROM tm.TaskItem
WHERE tm.TaskItem.TaskId = tm.Task.taskId
)
ELSE CreateDate
END
WHERE TaskId IN (
SELECT t.TaskId
FROM tm.Task t
INNER JOIN tm.Action tma ON tma.ActionId = t.ActionId
WHERE tma.InternalKey IN (
'ScanAudit'
,'STOCKOUTFA'
)
AND t.StartDate IS NULL
)