ผู้เขียน หัวข้อ: รบกวนช่วยตรวจดูคำสั่งด้วยครับ  (อ่าน 3163 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ teerapun_top

  • Sr. Member
  • ****
  • กระทู้: 353
  • คิดแล้วทำ ทำแล้วคิด
  • Respect: +1
    • ดูรายละเอียด
รบกวนช่วยตรวจดูคำสั่งด้วยครับ
« เมื่อ: กุมภาพันธ์ 20, 2013, 09:46:44 AM »
0
รบกวนช่วยดูคำสั่งด้วยครับ ว่าผิดตรงไหน  ทำให้ไม่สามารถหาค่าได้ครับ

select distinct cid as CardID, p.birthdate, body_weight as weight, height, if(sex='1','M', 'F') as Gender,

                        if(sex='1','ชาย', 'หญิง') as GenderName, nutrition_date as UpdDate, nutrition_date as TransactionDate,

                        school_name as SchoolID, '' ClassroomID, 0 RoomNumber

                        from person as p

                        inner join person_epi as pe on p.person_id=pe.person_id

                        inner join person_epi_nutrition as pen on pen.person_epi_id=pe.person_epi_id

                        left outer join village_student as vt on p.person_id=vt.person_id

                        left outer join village_school as vs on vs.village_school_id=vt.village_school_id

                        left join village_school_room as vsm on vs.village_school_id=vsm.village_school_id

                        where p.cid is not null and body_weight <> 0 and height <> 0

                        and pen.nutrition_date>=?1 and pen.nutrition_date<=?2

                        union

                        select distinct cid as CardID, p.birthdate, body_weight as weight, height, if(sex='1','M', 'F') as Gender,

                        if(sex='1','ชาย', 'หญิง') as GenderName, screen_date as UpdDate, screen_date as TransactionDate,

                        school_name as SchoolID,

                        if(village_school_class_name='อนุบาล1','อ.1',if(village_school_class_name='อนุบาล2','อ.2',

                        if(village_school_class_name='อนุบาล3','อ.3',if(village_school_class_name='ประถม1','ป.1',

                        if(village_school_class_name='ประถม2','ป.2',if(village_school_class_name='ประถม3','ป.3',

                        if(village_school_class_name='ประถม4','ป.4',if(village_school_class_name='ประถม5','ป.5',

                        if(village_school_class_name='ประถม6','ป.6',if(village_school_class_name='มัธยม1','ม.1',

                        if(village_school_class_name='มัธยม2','ม.2',if(village_school_class_name='มัธยม3','ม.3',

                        if(village_school_class_name='มัธยม4','ม.4',if(village_school_class_name='มัธยม5','ม.5',

                        'ม.6')))))))))))))) as ClassroomID,

                        if(school_room_no=0,1,if(school_room_no is null,1,Cast(school_room_no as Signed))) as RoomNumber

                        from village_student_screen as vss

                        left outer join village_student as vt on vss.village_student_id=vt.village_student_id

                        left outer join village_school as vs on vs.village_school_id=vt.village_school_id

                        left outer join village_school_class as vsc on vt.village_school_class_id=vsc.village_school_class_id

                        left outer join person as p on p.person_id=vt.person_id

                        left join village_school_room as vsm on vs.village_school_id=vsm.village_school_id

                        left outer join house as h on h.house_id=p.house_id

                        left outer join village as v on h.village_id=v.village_id

                        left outer join thaiaddress as d on v.address_id=d.addressid

                        where p.cid is not null and body_weight <> 0 and height <> 0 and chwpart is not null

                        and screen_date>=?1 and screen_date<=?2
นายธีรพันธ์ บวรสถิตย์  นักวิชาการสาธารณสุข
กลุ่มงานเวชปฎิบัติครอบครัวและชุมชน
โรงพยาบาลบ่อไร่  อำเภอบ่อไร่ จังหวัดตราด
-ดูแลระบบรายงาน 21/43 แฟ้มโรงพยาบาล
-ยังขาดประสบการณ์อีกเยอะต้องขอคำชี้แนะด้วยครับ
e-mail:teerapun_pbht@hotmail.com