Solved

Reference Alias in case statment

Posted on 2007-11-27
3
5,209 Views
Last Modified: 2010-04-21
Hi Experts,

I'm wondering if you can reference a  alias column (columns added together) within a case statement:

The aslias columns is S_NET_INCM.

Select  SCPL,    EIN,    SOI_MAJ_CD,   SOI_DIV_CD,
             NVL(NET_INCM, 0) +   NVL(S_NET_INCM_OTHR_RNTL, 0) +  NVL(S_NET_LTCG_LSS, 0) +
              NVL(S_NET_STCG_LSS, 0) AS "S_NET_INCM" ,
             NVL(NET_OTHR_INCM, 0),
             CASE
             WHEN  "S_NET_INCM: < 0 THEN
                  0
            ELSE
                 S_NET_INCM_POS
           END "S_NET_INCM_POS"
          FROM ENTITY_ADDITIONAL JOIN CONTROL C USING (SCPL, EDIT_1_2)

Thanks
           
0
Comment
Question by:lfolku
3 Comments
 
LVL 9

Accepted Solution

by:
joebednarz earned 125 total points
ID: 20359159
Something to try:


SELECT SCPL, EIN, SOI_MAJ_CD, SOI_DIV_CD, NET_OTHR_INCM,
       CASE
          WHEN S_NET_INCM < 0 THEN 0
          ELSE S_NET_INCM_POS
       END S_NET_INCM_POS
  FROM (SELECT SCPL, EIN, SOI_MAJ_CD, SOI_DIV_CD,
                 NVL (NET_INCM, 0)
               + NVL (S_NET_INCM_OTHR_RNTL, 0)
               + NVL (S_NET_LTCG_LSS, 0)
               + NVL (S_NET_STCG_LSS, 0) S_NET_INCM,
               NVL (NET_OTHR_INCM, 0) NET_OTHR_INCM
          FROM ENTITY_ADDITIONAL) A
       JOIN
       CONTROL C USING (SCPL, EDIT_1_2)

Open in new window

0
 
LVL 47

Expert Comment

by:schwertner
ID: 20359235
A possible workaround:

SELECT a.SCPL, a.EIN ....,
 CASE
             WHEN  "a.S_NET_INCM: < 0 THEN
                  0
            ELSE
                 S_NET_INCM_POS
           END "S_NET_INCM_POS"
FROM
(Select SCPL,    EIN,    SOI_MAJ_CD,   SOI_DIV_CD,
             NVL(NET_INCM, 0) +   NVL(S_NET_INCM_OTHR_RNTL, 0) +  NVL(S_NET_LTCG_LSS, 0) +
              NVL(S_NET_STCG_LSS, 0) AS "S_NET_INCM" ,
             NVL(NET_OTHR_INCM, 0) AS "NET_OTHR_INCM",
                        FROM ENTITY_ADDITIONAL JOIN CONTROL C USING (SCPL, EDIT_1_2)) a
0
 

Author Closing Comment

by:lfolku
ID: 31411214
It worked.....thanks!!!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to recover a database from a user managed backup

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question