Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5245
  • Last Modified:

Reference Alias in case statment

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
lfolku
Asked:
lfolku
1 Solution
 
joebednarzCommented:
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
 
schwertnerCommented:
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
 
lfolkuAuthor Commented:
It worked.....thanks!!!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now