Domanda

I was trying to convert the connect by level function of oracle to teradata. I have seen many examples over the net but this particular one is different,

 (SELECT 
     CASE LEVEL 
        WHEN 1 THEN 'MB'
        WHEN 2 THEN 'SB'
        ELSE 'TOTAL'
     END AS DRUG_SOURCE
 FROM
    DUAL 
 CONNECT BY LEVEL <= 3) RW  

Please let me know if you guys have any idea.

È stato utile?

Soluzione

Hey I found the solution for this. Sorry I couldn't explain my question clearly.

The below code would work exactly the way i wanted in teradata

select 'MB' as DRUG_SOURCE from dual  
union  
select 'SB' as DRUG_SOURCE from dual  
Union  
select 'TOTAL' as DRUG_SOURCE from dual  

Altri suggerimenti

You can try this code:

select DRUG_SOURCE from (select 'MB' as DRUG_SOURCE,1 as id) a
union all
select DRUG_SOURCE from (select 'SB' as DRUG_SOURCE,2 as id) b
union all
select DRUG_SOURCE from (select 'TOTAL' as DRUG_SOURCE,3 as id) c
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top