Use if in sql-server : I have a small query in my stored procedure:

(case when t.status =4 and (select top 1 nd.status from tableND nd where nd.Code= t.Code order by nd.ID desc)=4 
 then 6 else t.status end) as status 
from tableTC t

The problem is the speed performance too slow. So, I wanna change it into another query.
What should i do now ?