select
TR.business_date
,CEMP.obj_num [chk_emp_num]
,CEMP.last_name || ', ' || CEMP.first_name [chk_emp_name]
,AEMP.obj_num [auth_emp_num]
,AEMP.last_name || ', ' || AEMP.first_name [auth_emp_name]
,CHK.chk_num
,DTL.dtl_name
,(case
when DTL.ob_dtl05_void_flag = 'T' then 'void'
when MD.ob_dtl04_rtn = 'T' then 'return'
else 'other'
end) [trans_type]
,DTL.rpt_ttl
,coalesce(RR."name", VR."name", 'no reason') [reason]
from
micros.chk_dtl [CHK]
join micros.trans_dtl [TR]
on CHK.chk_seq = TR.chk_seq
join micros.dtl [DTL]
on TR.trans_seq = DTL.trans_seq
join micros.emp_def [CEMP]
on CHK.emp_seq = CEMP.emp_seq
left outer join micros.mi_dtl [MD]
on DTL.trans_seq = MD.trans_seq
and DTL.dtl_seq = MD.dtl_seq
left outer join micros.reason_def [RR]
on MD.return_dtl_id = RR.reason_seq
left outer join micros.reason_def [VR]
on DTL.reason_seq = VR.reason_seq
left outer join micros.emp_def [AEMP]
on DTL.auth_emp = AEMP.emp_seq
where
TR.business_date = '2014-10-27' [COLOR=#4E9A06]// change to whatever date you need[/color]
and (
DTL.ob_dtl05_void_flag = 'T'
or MD.ob_dtl04_rtn = 'T' [COLOR=#4E9A06]// comment this line out to show just voids[/color]
)
order by
CEMP.obj_num
,CHK.chk_num
,[trans_type]