How can I get the last items by date desc then by id desc?
Your query seem ok.

you should thoroughly Test the Resultset in all server.

Only concern is that when it is ISNULL then Why you will update with 0.Is it really necessary ?

Also second CTE is not required.

WITH History AS (
    SELECT  Id, h.EmployeeId, CompanyCourseId, NextDueDate, HasAttachments, 
        ROW_NUMBER() OVER (Partition BY EmployeeId,CompanyCourseId ORDER BY 
        NextDueDate DESC, Id DESC) AS rownum
    FROM TrainingHistory h
)

 select ec.Id, l.HasAttachments
  INTO TempEmployeeCourse from History l INNER JOIN 
      EmployeeCourse ec on l.CompanyCourseId = ec.CompanyCourseId AND 
      l.EmployeeId = ec.EmployeeId
where WHERE l.rownum = 1


update EC
set HasAttachments =TEC.HasAttachments 
,UniqueId =TEC.UniqueId  
from EmployeeCourse EC
inner join dbo.TempEmployeeCourse TEC 
on TEC.Id =EC.EmployeeCourse.Id