BMS-HOSxP Community

HOSxP => การเขียน SQL Script => ข้อความที่เริ่มโดย: Guitar-hero ที่ กุมภาพันธ์ 10, 2010, 20:55:04 PM

หัวข้อ: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: Guitar-hero ที่ กุมภาพันธ์ 10, 2010, 20:55:04 PM
คือผมต้องการปรับปรุงข้อมูลบางอย่างในตาราง ovst โดยปรับปรุงเฉพาะเดือนครับ คำสั่งที่ผมใช้เป็นดังนี้

update ovst set spclty='01'

where  main_dep='13' and vstdate between '2009-06-01' and '2009-06-01'

แต่มันดึึงมาทั้งหมดครับ มันไม่เลือกมาเฉพาะเดือนที่เลือก ไม่ทราบว่าผมเขียนคำสั่งผิดตรงไหน มือใหม่ครับ ช่วยแนะนำหน่อยครับ
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: skypec ที่ กุมภาพันธ์ 10, 2010, 22:35:20 PM
ลองทดสอบแล้ว ข้อมูลก็มาเฉพาะวันที่กำหนดเองนะครับ
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: saiphon ที่ กุมภาพันธ์ 10, 2010, 22:45:23 PM
ก็น่าจะถูกต้องแล้วนะครับ
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: Svl2Nuk3 ที่ กุมภาพันธ์ 17, 2010, 00:34:18 AM
น่าจะแก้ข้อมูลใน vn_stat   ด้วยนะครับ
เพราะหลาย ๆ รายงานมักจะดึงข้อมูลจากตารางนี้  เพื่อลดความซ้ำซ้อนของคำสั่งในการดึงข้อมูล
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: yord ที่ กุมภาพันธ์ 22, 2010, 13:53:14 PM
น่าจะได้แล้วนะครับ ของผมใช้แบบนี้
update ovst set spclty = '01' where main_dep = "052" and vstdate = "2009-04-09"
แต่ว่าช้าครับ กำลังจะทำแบบว่า ให้ update spclty ทั้งหมดที่ว่างอยู่ โดยให้ไปอิงกับ ตาราง kskdepartment เพราะว่ามี spclty ที่เป็นค่าว่า่งมากเหมือนกันครับ
ลองอยู่ 2 คำสั่งแต่ยังไม่ได้เลยครับ ;D
 ;Dupdate ovst set spclty =
(select spclty from kskdepartment where kskdepartment.dep = ovst.cur_dep)
where cur_dep in (select cur_dep from ovst where ovst.cur_dep = kskdepartment.dep and
ovst.spclty < "0" and ovst.vstdate = "2009-04-09")

update ovst set spclty = (select kskdepartment.spclty from kskdepartment,ovst
where kskdepartment.depcode=ovst.cur_dep)
where spclty < "0" and vstdate = "2009-04-09"
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: yord ที่ กุมภาพันธ์ 23, 2010, 15:20:58 PM
วันนี้ก็ยังไม่ได้เหมือนกัน ;D
ขอดันครับ เผื่อ อ.ท่านใดทำได้แล้วครับะ ;D
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: yord ที่ มีนาคม 03, 2010, 09:55:41 AM
ท่านใดลองแล้วได้ผล รบกวนด้วยครับ ???
เพราะฟิลด์คลินิก ของผมว่างเยอะครับ(เกิดจากตอนนัด แล้วไม่ได้ใส่คลินิก เมื่อส่ง visit ล่วงหน้าก็เลยไม่มี คลินิกออกมาน่ะครับ) เดี๋ยวส่งข้อมูลแล้วมีปัญหาน่ะครับ ;D ;D ;D
หัวข้อ: Re: สอบถามอาจารย์ทุกท่านเกี่ยวกับการใช้คำสั่ง sql update
เริ่มหัวข้อโดย: yord ที่ มีนาคม 03, 2010, 19:03:49 PM
ตอนนี้ก็ทำแบบนี้ไปก่อนครับ  ;D
update ovst set spclty = "01" where (main_dep = "002" or main_dep = "003" or main_dep ="007" or main_dep = "009" or main_dep = "010" or main_dep = "012" or main_dep = "013" or main_dep = "014" or main_dep = "015" or main_dep = "016" or main_dep = "017" or main_dep = "019" or main_dep = "020" or main_dep = "021" or main_dep = "025" or main_dep = "027" or main_dep = "029" or main_dep = "030" or main_dep = "033" or main_dep = "039" or main_dep = "040" or main_dep = "043" or main_dep = "044" or main_dep = "049" or main_dep = "050" or main_dep = "061" or main_dep = "064" or main_dep = "065" or main_dep = "070" or main_dep = "071" or main_dep = "072" or main_dep = "073" or main_dep = "074" or main_dep = "076" or main_dep = "079" or main_dep = "084" or main_dep = "111" or main_dep = "112" or main_dep = "113" or main_dep = "124") and spclty < "0" and (vstdate between "2009-10-01" and "2009-10-31")
ประมาณนี้ อ่ะครับ ข้อมูลจะได้สมบูรณ์  ;D ;D ;D