Hi All,
this is my first post on any forum.
It would be great if someone can tell me whether to use OR or a UNION when both are giving same results.
Also i want to know is the use of CASE statement like below correct ?
here are two queries that I am talking about
1
+++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
'FAILED' status,
'CR' trx_type,
'P2P' eventstatuscode,
src.devicenumber display_device,
FROM transactionevent a, account src
WHERE a.tgtaccountid =:srcaccountid
AND a.eventstatuscode IN ('abc')
AND a.transtypecode = 'P2P'
AND src.id = a.srcaccountid
UNION
'FAILED' status,
'DR' trx_type,
'P2P' eventstatuscode,
tgt.devicenumber display_device
FROM transactionevent a, account tgt,
WHERE a.srcaccountid =:srcaccountid
AND a.eventstatuscode IN ('abc')
AND a.transtypecode = 'P2P'
AND tgt.id = a.tgtaccountid
++++++++++++++++++++++++++++++++++++++++++++++++++ +
2
++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
'FAILED' status,
(CASE
WHEN src.id = a.tgtaccountid THEN 'DR'
WHEN src.id = a.srcaccountid THEN 'CR'
END ) trx_type,
'P2P' eventstatuscode,
src.devicenumber display_device
FROM transactionevent a, account src
WHERE ( a.tgtaccountid =:srcaccountid OR a.srcaccountid=:srcaccountid )
AND a.eventstatuscode IN ('abc')
AND a.transtypecode = 'P2P'
AND src.id = (CASE
WHEN a.srcaccountid =:srcaccountid then a.tgtaccountid
WHEN a.tgtaccountid =:srcaccountid then a.srcaccountid
END
)
++++++++++++++++++++++++++++++++++++++++++++++++++