update tbcase
set hivresult=0
where exists(select * from examhiv a where a.case_id = tbcase.id and result=0)
update tbcase
set hivresult=1
where exists(select * from examhiv a where a.case_id = tbcase.id and result = 1)
and hivresult is null
update tbcase
set hivresult=2
where exists(select * from examhiv a where a.case_id = tbcase.id and result = 2)
and hivresult is null
update tbcase
set hivresult=3 where hivresult is null
update tbcase
set startedartdate = (select min(startedartdate) from examhiv a where a.case_id=tbcase.id)
update tbcase
set startedcptdate = (select min(startedcptdate) from examhiv a where a.case_id=tbcase.id)