select T4.TDDOC,
T4.tddsc1,
t4.tddsc2,
t4.tddsc,
t4.uorg,
t4.tuprc,
t4.taexp,
t4.THDC5801,
t4.tddoco,
t4.thflag,
t4.tdtxa1,
t4.tdflag,
t4.THSTRING01,
t2.tdtxa2,
t3.mcu,
trim(c.abalph) as abalph,
t4.thalph
from (select trim(t1.tddoc) as tddoc,
trim(t1.tddsc1) AS tddsc1,
trim(t1.tddsc2) as tddsc2,
trim(t1.tddsc) as tddsc,
T1.TDUORG / 10000 as uorg,
T1.TDTUPRC / 10000 as tuprc,
T1.TDTAEXP / 100 as taexp,
trim(T.THDC5801) as THDC5801,
t1.tddoco,
t.thflag,
t1.tdtxa1,
trim(t.thalph) as thalph,
t1.tdflag,
T.THSTRING01
from proddta.f5842001 t
left join proddta.f5842002 t1
on t.thdoc = t1.tddoc
where 1=1 ${if(len(单据号)==0,"","and t.tHdoc='"+单据号+"'")}
and 1=1 ${if(len(单据号上)==0,"","and t.tHdoc>'"+单据号上+"'")}
and 1=1 ${if(len(单据号下)==0,"","and t.tHdoc<'"+单据号下+"'")}
and t1.tdchar01 <> 'N'
) t4
left join (select tddoc,
listagg(to_char(tdtxa1), ' ') WITHIN GROUP(ORDER BY tdtxa1) AS tdtxa2
from (select distinct tddoc, concat(SUBSTR(trIM(tdtxa1), 2, 2), '%') as tdtxa1
from proddta.f5842002)
group by tddoc) t2
on t4.tddoc = t2.tddoc
left join (select tddoc,listagg(to_char(tdmcu), ' ') WITHIN GROUP(ORDER BY tdmcu) AS mcu
from (select distinct tddoc, trIM(tdmcu) as tdmcu
from proddta.f5842002)
group by tddoc) t3
on t4.tddoc = t3.tddoc
left join sy920.f0092 b
on T4.thstring01= b.uluser
left join proddta.f0101 c
on b.ulan8 = c.aban8
order by t4.tddoc, t4.tdtxa1