select r1.name as HN,r1.name1 as Pt_Name,r1.name2 as Pt_Age,r1.name3 as FullAddress,r1.name4 as Sex,r1.date1 as BirthDay,
r2.name as Occupation,r2.name1 as MarryStatus,r2.name2 as Nationality,r2.name3 as Citizenship,r2.name4 as Religion,
r3.name as BloodGroup,r3.name1 as DrugAllergy,r3.name2 as HomeTel,r3.name3 as InformName,r3.name4 as InformAddr,
r4.name as InformRelation,r4.name1 as Father,r4.name2 as Mother,r4.name3 as SPSName,r4.name4 as CardName,
r5.name as CardCODE,r5.name1 as PtRight,r5.name2 as PtRightCode,r5.date1 as RightExpire,
p.po_code,p.pname,p.fname,p.lname
from tempreport r1
left outer join tempreport r2 on r2.reportname=r1.reportname and r2.id=r1.id and r2.num=2
left outer join tempreport r3 on r3.reportname=r1.reportname and r3.id=r1.id and r3.num=3
left outer join tempreport r4 on r4.reportname=r1.reportname and r4.id=r1.id and r4.num=4
left outer join tempreport r5 on r5.reportname=r1.reportname and r5.id=r1.id and r5.num=5
left outer join patient p on p.hn=r1.name
where
r1.id="ID-{7A982941-8457-46C2-B99F-839EFFDFA90D}" and
r2.id="ID-{7A982941-8457-46C2-B99F-839EFFDFA90D}" and
r3.id="ID-{7A982941-8457-46C2-B99F-839EFFDFA90D}" and
r4.id="ID-{7A982941-8457-46C2-B99F-839EFFDFA90D}" and
r5.id="ID-{7A982941-8457-46C2-B99F-839EFFDFA90D}" and
r1.reportname="RB1T02" and r1.num=1
limit 1