Is it possible to do a Decode statement within a Where clause? I'm trying to write SQL that will pull the Branch code from 2 different tables. If it's Null within the Trx table then pull from the Sales table.
I tried doing an Or clause such as below, but it pulls double if it's in both tables for 1 request.
AND (TRXINFO.FIN_TRX_BRANCH_ID = MB.MANDI_BRANCH_ID
OR FRI.REQ_SALES_OFFICE_CODE = MB.MANDI_BRANCH_ID)
Here is my so called Decode statement within a where clause.
AND DECODE(TRXINFO.FIN_TRX_BRANCH_ID, NULL, FRI.REQ_SALES_OFFICE_CODE = MB.MANDI_BRANCH_ID,
TRXINFO.FIN_TRX_BRANCH_ID = MB.MANDI_BRANCH_ID)
Can someone help with this concept or give me ideas?
I'd be happier if you posted some more relevant information (for example, Oracle database version, CREATE TABLE and INSERT INTO sample data statements) so that it would be easier to do it for you.
Now I tried to create a *working* query which might server as an example for you - see if it suits your needs and, if so, try to implement it into your case. The general idea is what you wanted - the only difference is using the CASE instead of DECODE.
SQL> select ename
2 from emp e
3 where e.deptno = case when mgr is null then
4 (select deptno from dept where loc = 'BOSTON')
6 (select deptno from dept where loc = 'NEW YORK')