BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: panus_t ที่ ตุลาคม 30, 2013, 14:14:49 PM
-
ช่วยตรวจสอบคำสั่ง Update Person.Patient.hn ให้หน่อยครับ
ไม่ทราบว่าผมสามารถ update patient link แบบนี้เลยได้หรือเปล่าครับ
update
person p
set p.patient_hn=select pp.hn from patient pp where pp.cid<>"1111111111111" and pp.cid is not null
left outer join patient pt on pt.cid=p.cid
where p.patient_link="Y",p.patient_hn="" or p.patient_hn is null and pt.cid<>"1111111111111" and pt.cid is not null
-
update person ps
join patient pt on pt.cid=ps.cid
set ps.patient_hn=pt.hn
where pt.cid <> "1111111111111" and pt.cid is not null and ps.patient_link="Y" and ps.patient_hn=""
-
;D ขอบคุณมากครับ
-
ขอบคุณครับ แล้วถ้าจะเพิ่มเงื่อนไขให้ตรวจสอบ ชื่อ และสกุล ใน Person กับ Patient ต้องตรงกันด้วย ทำไงครับ
เพราะบางทีเจอว่าคนชื่อ ชื่อสกุลแต่ CID เดียวกัน (หรืออาจจะเปลี่ยนชื่อสกุลก็ได้ แต่ขอถามเจ้าตัวก็ครับ ก็เลยไม่อยากให้ update ในส่วนของชื่อ-สกุลไม่ตรงกันใน 2 ตารางดังกล่าวครับ)
;D
-
ขอบคุณครับ แล้วถ้าจะเพิ่มเงื่อนไขให้ตรวจสอบ ชื่อ และสกุล ใน Person กับ Patient ต้องตรงกันด้วย ทำไงครับ
เพราะบางทีเจอว่าคนชื่อ ชื่อสกุลแต่ CID เดียวกัน (หรืออาจจะเปลี่ยนชื่อสกุลก็ได้ แต่ขอถามเจ้าตัวก็ครับ ก็เลยไม่อยากให้ update ในส่วนของชื่อ-สกุลไม่ตรงกันใน 2 ตารางดังกล่าวครับ)
;D
ลองดู
update person ps
join patient pt on pt.cid=ps.cid
set ps.patient_hn=pt.hn
where pt.cid <> "1111111111111" and pt.cid is not null and ps.patient_link="Y" and ps.patient_hn="" and concat(pt.fname,pt.lname)=concat(ps.fname,ps.lname)