อ.MN เคยบอกผมไว้แบบนี้ครับ
update patient set cid = (select replace(cardno,'-','') from ptcardno
where ptcardno.hn = patient.hn and ptcardno.cardtype='01' and ptcardno.cardno not like '1-1111-11111-11-%')
where hn in (select hn from ptcardno where ptcardno.hn = patient.hn
and ptcardno.cardtype='01' and ptcardno.cardno not like '1-1111-11111-11-%' )
and cid is null
and patient.hn between '0000013' and '0009111'