Try this.
createtable #temp1(patno int, hospno int, roomcode bit)createtable #temp2(patno int, hospno int, proc_code int)createtable #temp3(proc_code int, department int)insertinto #temp1select 1, 123, nullunionselect 1, 124,nullinsertinto #temp2select 1, 123, 256unionselect 1, 123, 258unionselect 1, 123, 300unionselect 1, 124, 500insertinto #temp3select 258, 701unionselect 200, 701Update t1 set roomcode=1from #temp1 t1innerjoin #temp2 t2 on t1.patno = t2.patno and t1.hospno = t2.hospnoinnerjoin #temp3 t3 on t3.proc_code = t2.proc_codeselect * from #temp1
Vinay Valeti| If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer