Please can you take a look at this query and point out what I'm doing wrong:
update @output
set fromdate = o.fromdate,
todate = o.todate
from
(
select fromdate, max(todate)
from @output as o
left join status as es on
o.number = es.empid and
o.ccode = es.compcode and
@status = es.status
)
I'm trying to update @output with the record thats contains the max(todate). The error I'm getting is:
Msg 156, Level 15, State 1, Procedure CHP_OR_PENSIONEMPLOYEEENROLMENT_842, Line 138 Incorrect syntax near the keyword 'select'.