select * from
(
select ITSDATE, SOURCEID, SOURCETYPE, ACCDEBIT as ACC, SUBACCDEBIT as SUBACC, DEBIT as ITSTOTAL, 1 as ISDEBIT,
ACCCREDIT as CORACC, ACCOUNT.ITSNAME as CORACCNAME, ACCOUNT.ITSNUMBER as CORACCNUMBER, SUBACCCREDIT as CORSUBACC, ACCOUNTINGENTRY.DESCRIPTION 
from ACCOUNTINGENTRY 
join ACCOUNT on ACCOUNTINGENTRY.ACCDEBIT = ACCOUNT.ITSID
where ACCDEBIT=:ACCID :SUBACCDEBIT and ITSDATE >=:DATE1 and ITSDATE<=:DATE2

union all

select ITSDATE, SOURCEID, SOURCETYPE, ACCCREDIT as ACC, SUBACCCREDIT as SUBACC, CREDIT as ITSTOTAL, 0 as ISDEBIT,
ACCDEBIT as CORACC, ACCOUNT.ITSNAME as CORACCNAME, ACCOUNT.ITSNUMBER as CORACCNUMBER, SUBACCDEBIT as CORSUBACC, ACCOUNTINGENTRY.DESCRIPTION 
from ACCOUNTINGENTRY 
join ACCOUNT on ACCOUNTINGENTRY.ACCCREDIT = ACCOUNT.ITSID
where ACCCREDIT=:ACCID :SUBACCCREDIT and ITSDATE >=:DATE1 and ITSDATE<=:DATE2
) as UNION_DETAIL
order by ITSDATE;
