Solved

Reference Alias in case statment

Posted on 2007-11-27
3
5,197 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
Comment Utility
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
Comment Utility
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
Comment Utility
It worked.....thanks!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now