UPDATE a SET a.AssignUserID=b.UserID FROM LeadsTask a INNER JOIN ProjectTask_Employee b ON a.TaskID=b.PTID WHERE a.Status=2 AND ISNULL(a.AssignUserID,-2)<0 AND ISNULL(b.UserID,-2)>0