BMS-HOSxP Community
HOSxP => แจ้งปัญหา / ขอความช่วยเหลือ => ข้อความที่เริ่มโดย: Oct. Man ที่ ธันวาคม 09, 2010, 11:51:04 AM
-
เรื่องมีอยู่ว่าที่โรงพยาบาลที่ผมทำงาน มีการโอนข้อมูลจากโปรแกรมอื่นมายัง hosxp ตอนขึ้นระบบ ทำให้ข้อมูลบางฟิวด์ไม่ถูกต้อง เช่น fathername โดยปกติใน hosxp จะมีเฉพาะชื่ออย่างเดียวแต่ตอนนี้จะอยู่ในรูปแบบ (ชื่อ นามสกุล ) จึงอยากขอคำแนะนำจากอาจารย์ทั้งหลายเพื่อเป็นแนวทางในการแก้ไขให้ถูกต้องครับ จะเป็นตามรูปอ่ะครับ ตอนนี้ผมใช้วิธีแบบอนุบาลคือเชื่อมโยงกับ odbc แล้วนั่งแก้ทีละคนอยู่ครับ :) :) :)
-
update query จากตารางอ้างอิงที่เชื่อถือได้ไปยังตาราง person ในfield father & mother
-
มันไม่มีนะซิครับ ตารางที่จะอ้างอิงและเชื่อถือได้ เพราะว่าถ้าใน Patient ผิดใน Person ก็ไม่น่าจะถูกครับ :)
-
ดึงข้อมูลออกมาจาก fathername เก็บค่าไว้ในตัวแปร จากนั้นแยกชื่อกับนามสกุลออกจากกัน ไปเก็บไว้ในตัวแปรอีก 2 ตัวที่เตรียมไว้ โดยใช้ช่องว่างระหว่างชื่อกับนามสกุลเป็นตัวแยกแยะ ซึ่งก็จะทำให้ได้ข้อมูลออกมาแล้ว 2 ตัวแปรเสร็จแล้วก็เอาชื่อไป update ให้ fathername และเอานามสกุลที่ได้ไป update ให้ fatherlname ทำแบบนี้ทีละreccord ครับ ใช้สคริป pascal ทำน่ะครับ
-
ลองทดสอบก่อนนะครับ ผมยังไมม่ได้ทดสอบ เขียนสดใน notepad
update patient
set fathername = left(fathername,instr(fathername," ")),
fatherlname = right(fathername,length(fathername)-instr(fathername," ")+1)
หรือ
update patient
set fathername = left(fathername,instr(fathername," ")),
fatherlname = substr(fathername,instr(fathername," ")+1)
-
ขอบคุณครับ เดี๋ยวลองดูครับ น่าจะพอดัดแปลงมาใช้ได้ครับ แต่ข้อมูลมันไม่เหมือนกันทั้งหมดนะซิครับ บางส่วนก็ถูกอยู่แล้ว :) :) :)
-
ถ้าจะตัดออกอ่ะครับ สมมุติว่าผมจะลบข้อมูลในส่วนที่ 1 และส่วนที่ 2 ออกจะใช้คำสั่งอย่างไรครับ :)
-
ลอง select hn,fathername,fatherlname
,left(fathername,instr(fathername,' ')) 'test1'
,substr(fathername,instr(fathername,' ')+1) 'test2'
from patient
where locate(' ',trim(fathername))>1
limit 1000
ดูก่อน แล้วค่อย Update
1.update patient set fatherlname=fathername where where locate(' ',trim(fathername))>1
2.update patient set fatherlname=left(fathername,instr(fathername,' ')),fatherlname=substr(fatherlname,instr(fatherlname,' ')+1) where where locate(' ',trim(fathername))>1
ระมัดระวังหน่อยนะคับ
-
ลอง select hn,fathername,fatherlname
,left(fathername,instr(fathername,' ')) 'test1'
,substr(fathername,instr(fathername,' ')+1) 'test2'
from patient
where locate(' ',trim(fathername))>1
limit 1000
ดูก่อน แล้วค่อย Update
1.update patient set fatherlname=fathername where where locate(' ',trim(fathername))>1
2.update patient set fatherlname=left(fathername,instr(fathername,' ')),fatherlname=substr(fatherlname,instr(fatherlname,' ')+1) where where locate(' ',trim(fathername))>1
ระมัดระวังหน่อยนะคับ
ขอบคุณมากครับ ลองทำดูแล้วครับตอน select ดูเนี่ย ok นะครับ แต่ตอน update เนี่ยยังไม่ค่อยถูกจะลองเช็คดูคำสั่งอีกทีนึงครับ :)
-
คำสั่งมันผิดอยู่นิดนึงครับ เผื่อท่านอื่นจะเอาไปใช้ :)
ตามนี้ครับ
select hn,fathername,fatherlname
,left(fathername,instr(fathername,' ')) 'test1'
,substr(fathername,instr(fathername,' ')+1) 'test2'
from patient
where locate(' ',trim(fathername))>1
limit 1000
select hn,mathername,motherlname
,left(mathername,instr(mathername,' ')) 'test1'
,substr(mathername,instr(mathername,' ')+1) 'test2'
from patient
where locate(' ',trim(mathername))>1
limit 1000
.........
1.update patient set fatherlname=fathername where locate(' ',trim(fathername))>1
2.update patient set fatherlname=left(fathername,instr(fathername,' ')),fatherlname=substr(fatherlname,instr(fatherlname,' ')+1) where locate(' ',trim(fathername))>1
1.update patient set motherlname=mathername where locate(' ',trim(mathername))>1
2.update patient set motherlname=left(mathername,instr(mathername,' ')),matherlname=substr(matherlname,instr(matherlname,' ')+1) where locate(' ',trim(mathername))>1