Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 02, 2011 06:45 AM by firstname.lastname@example.org
Jun 01, 2011 04:41 PM|LINK
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
Jun 02, 2011 06:09 AM|LINK
SELECT COALESCE(column5, column4, column3, column2) AS Output
Jun 02, 2011 06:45 AM|LINK
FINALLY I RESOLVED IT BY
WHEN COL4 <> '' THEN COL4
WHEN COL3 <> '' THEN COL3
WHEN COL2 <> '' THEN COL2
WHEN COL1 <> '' THEN COL1
END AS OUTPUT FROM MYTABLE;