Select
tbl_contact.contact_code,
contact_title
||'.'||contact_name contact_name,
contact_address,
contact_pcode,
city_name city_name,
country_name,
contact_ph_mob,
contact_ph_res,
contact_ph_off,
contact_email,
contact_fax,
donation_date,
purpose_name,
Decode(donation_payment_mode,'CH','Cheque','CA','Cash',
'PO','Postal Order','CC','Credit/Debit Card','DD',
'Deposit in Bank') payment_mode
,appeal_code
,donation_book_no
,donation_receipt_no
,donation_sr_no
,campaign_name
,tbl_category_detail.category_amount
,currency_symbol cur_symbol
From
(Select distinct
c.contact_code
,c.contact_title||' '||c.contact_name
,c.contact_address
,c.contact_pcode
,ci.city_name
,cy.country_name
,c.contact_ph_mob
,c.contact_ph_res
,c.contact_ph_off
,c.contact_email
,c.contact_fax
,d.donation_date
,cm.campaign_name
,d.appeal_code
,a.appeal_name
,p.purpose_name
,Decode(d.donation_payment_mode,'CH','Cheque','CA','Cash',
'PO','Postal Order','CC','Credit/Debit Card','DD',
'Deposit in Bank') payment_mode
,d.donation_book_no
,d.donation_receipt_no
,d.donation_sr_no
,cd.category_amount
,cu.currency_symbol
From
tbl_donation d
, tbl_category_detail cd
, tbl_contact c
, tbl_city ci
, tbl_country cy
, tbl_currency cu
, tbl_purpose p
, tbl_appeal a
, tbl_campaign cm
where 1 = 1
and
d.contact_code= c.contact_code(+)
and
d.donation_code = cd.donation_code(+)
and
d.currency_code= cu.currency_code(+)
and
c.city_code= ci.city_code(+)
and
ci.country_code= cy.country_code(+)
and
d.purpose_code = p.purpose_code(+)
and
d.appeal_code = a.appeal_code(+)
and
d.campaign_code = cm.campaign_code(+)
UNION ALL
Select distinct
c.contact_code
,c.contact_title||' '||c.contact_name
,c.contact_address
,c.contact_pcode
,ci.city_name
,cy.country_name
,c.contact_ph_mob
,c.contact_ph_res
,c.contact_ph_off
,c.contact_email
,c.contact_fax
,d.direct_debit_code
,dd.dd_start_date
,dd.dd_end_date
,dd.dd_detail_amount
,null donation_date
,cm.campaign_name
,null appeal_code
,null appeal_name
,vp.program_name
,null purpose_name
,null donation_payment_mode
,null donation_book_no
,null donation_receipt_no
,null donation_sr_no
,null category_amount
,cu.currency_symbol
From
tbl_contact c
,tbl_city ci
,tbl_country cy
,tbl_direct_debit d
,tbl_dd_detail dd
,tbl_campaign cm
,tbl_currency cu
,vew_program vp
Where 1=1
and
c.contact_code= d.contact_code(+)
and
d.direct_debit_code = dd.dd_detail_code(+)
and
dd.currency_code= cu.currency_code(+)
and
c.city_code= ci.city_code(+)
and
ci.country_code= cy.country_code(+)
and
dd.program_code = vp.program_code(+)
and
dd.campaign_code = cm.campaign_code(+)
and
c.contact_code between 240 and 1003
)