รบกวนช่วยดูคำสั่งด้วยครับ ว่าผิดตรงไหน ทำให้ไม่สามารถหาค่าได้ครับ
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