update t1
set roomcode = 1
from #temp1 t1
inner join #temp2 t2 on (t1.patno = t2.patno and t1.hospno = t2.hospno)
inner join #temp3 t3 on (t3.proc_code = t2.proc_code)
set roomcode = 1
from #temp1 t1
inner join #temp2 t2 on (t1.patno = t2.patno and t1.hospno = t2.hospno)
inner join #temp3 t3 on (t3.proc_code = t2.proc_code)