How to convert connect by level in teradata
-
03-03-2021 - |
Question
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.
Solution
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
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow