Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 02, 2011 06:45 AM by winseealn@hotmail.com
Participant
840 Points
1042 Posts
Jun 01, 2011 04:41 PM|LINK
hi all,
in my table more than 5 columns are there.now i want to show
if column5 has data then show that column with the alias name as "Output"
else if column4 has data then show that column with the alias name as "Output"
else if column3 has data then show that column with the alias name as "Output"
else show column2
how to write the sql query for the above condition
Star
9385 Points
1644 Posts
Jun 02, 2011 06:09 AM|LINK
SELECT COALESCE(column5, column4, column3, column2) AS Output FROM MyTable
Jun 02, 2011 06:45 AM|LINK
FINALLY I RESOLVED IT BY
SELECT CASE WHEN COL4 <> '' THEN COL4 WHEN COL3 <> '' THEN COL3 WHEN COL2 <> '' THEN COL2 WHEN COL1 <> '' THEN COL1 END AS OUTPUT FROM MYTABLE;
winseealn@ho...
Participant
840 Points
1042 Posts
find the data holding column
Jun 01, 2011 04:41 PM|LINK
hi all,
in my table more than 5 columns are there.now i want to show
if column5 has data then show that column with the alias name as "Output"
else if column4 has data then show that column with the alias name as "Output"
else if column3 has data then show that column with the alias name as "Output"
else show column2
how to write the sql query for the above condition
chohmann
Star
9385 Points
1644 Posts
Re: find the data holding column
Jun 02, 2011 06:09 AM|LINK
winseealn@ho...
Participant
840 Points
1042 Posts
Re: find the data holding column
Jun 02, 2011 06:45 AM|LINK
FINALLY I RESOLVED IT BY
SELECT CASE
WHEN COL4 <> '' THEN COL4
WHEN COL3 <> '' THEN COL3
WHEN COL2 <> '' THEN COL2
WHEN COL1 <> '' THEN COL1
END AS OUTPUT FROM MYTABLE;