DB2 Query

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
A_SUSHMA
Participant
Posts: 43
Joined: Fri Apr 12, 2013 10:34 am

DB2 Query

Post by A_SUSHMA »

Hi All,

Empno|Ename|Salary|Location
101 |Reddy|100000|Hyd
102 |John |200000|Delhi
103 |peter|000000|bangalore

One column need to displayed into two columns as per the below queries

Select empno,salary from emp where Ename =Peter

select empno,salary from emp where Ename=Reddy

based on the above conditions peters salary come in one column and reddy salary come in other column as below


Output

empno |salary|Alias salary
103 |NULL |0000000
101 |100000|NULL
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Are you selecting only two rows?

Code: Select all

Select empno,NULL,salary from emp where Ename =Peter 
Union All
select empno,salary,NULL from emp where Ename=Reddy 
You are the creator of your destiny - Swami Vivekananda
A_SUSHMA
Participant
Posts: 43
Joined: Fri Apr 12, 2013 10:34 am

Post by A_SUSHMA »

Union ALL will not work.I want to split the columns did you see my output?
empno |salary|Alias salary
103|NULL |0000000
101 |100000|NULL
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Explain your rules for determining when something is a "Salary" and something is an "Alias Salary" so people can stop guessing. After that, it just seems to me that it would just be if-then-else derivations using those rules.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply