BMS-HOSxP Community

HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: panus_t ที่ มกราคม 16, 2012, 14:18:23 PM

หัวข้อ: ตาราง ptcardno มี hn ซ้ำกันได้หรือเปล่าครับ
เริ่มหัวข้อโดย: panus_t ที่ มกราคม 16, 2012, 14:18:23 PM
ตาราง ptcardno มี hn ซ้ำกันได้หรือเปล่าครับ
ผมใช้คำสั่ง
select hn,count(hn) as c_hn from ptcardno group by hn
แล้วกรอง c_hn = 2 ได้ถึง 85491 record

เวลาเขียนรายงาน hn เหล่านี้จะออก 2 บรรทัดครับ
select ipt.an,ipt.hn,ipt.regdate,ipt.regtime,ipt.dchdate,ipt.dchtime,ipt.pttype,concat(pt.pname,pt.fname,"   ",pt.lname) as pt_name,ptc.cardno,ptt.name
from ipt ipt
left outer join patient pt  on pt.hn=ipt.hn
left outer join ptcardno ptc on ptc.hn=ipt.hn
left outer join pttype ptt on ptt.pttype=ipt.pttype
where ipt.dchdate between '2008-03-18' and '2008-03-18' and ipt.ward="07"
order by ipt.dchdate asc
หรือว่าผมต้องเขียนทำสั่ง sql อย่างไรครับ

อาจจะเกิดจากการใส่เลขบัตรประชาชน และเลขที่ต่างด้าว ที่หน้าประวัติทั่วไป
ต้องการให้โปรแกรม Lock ให้คีย์อย่างใดอย่างหนึ่งได้หรือเปล่าครับ
หัวข้อ: Re: ตาราง ptcardno มี hn ซ้ำกันได้หรือเปล่าครับ
เริ่มหัวข้อโดย: วีระวัฒน์ (เอก) ที่ มกราคม 16, 2012, 15:00:07 PM
ได้ครับ กรณี ไม่ใช้ คนไทย
เช่น

3-5000-00028-46-5     cardtype="01"   เลขประชาชน ทั่วไป

35-0000-002846-5      cardtype="02"   เลขต่างด้าว

แก้ใหม่เป็น
select ipt.an,ipt.hn,ipt.regdate,ipt.regtime,ipt.dchdate,ipt.dchtime,ipt.pttype,concat(pt.pname,pt.fname,"   ",pt.lname) as pt_name,ptc.cardno,ptt.name
from ipt ipt
left outer join patient pt  on pt.hn=ipt.hn
left outer join ptcardno ptc on ptc.hn=ipt.hn and ptc.cardtype="01"
left outer join pttype ptt on ptt.pttype=ipt.pttype
where ipt.dchdate between '2008-03-18' and '2008-03-18' and ipt.ward="07"
order by ipt.dchdate asc