find the data holding columnhttp://forums.asp.net/t/1685976.aspx/1?find+the+data+holding+columnThu, 02 Jun 2011 06:45:09 -040016859764441395http://forums.asp.net/p/1685976/4441395.aspx/1?find+the+data+holding+columnfind the data holding column <p>hi all,</p> <p>in my table more than 5 columns are there.now i want to show </p> <p>if column5 has data then show that column with the alias name as &quot;Output&quot;</p> <p>else if column4 has data then show that column with the alias name as &quot;Output&quot;</p> <p>else if column3 has data then show that column with the alias name as &quot;Output&quot;</p> <p>else show column2</p> <p>&nbsp;how to write the sql query for the above condition</p> 2011-06-01T16:41:38-04:004442079http://forums.asp.net/p/1685976/4442079.aspx/1?Re+find+the+data+holding+columnRe: find the data holding column <pre class="prettyprint">SELECT COALESCE(column5, column4, column3, column2) AS Output FROM MyTable</pre> 2011-06-02T06:09:06-04:004442130http://forums.asp.net/p/1685976/4442130.aspx/1?Re+find+the+data+holding+columnRe: find the data holding column <p>FINALLY I RESOLVED IT BY</p> <p>SELECT&nbsp; CASE <br> &nbsp;&nbsp;&nbsp;&nbsp;WHEN COL4 &lt;&gt; '' THEN COL4&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;WHEN COL3 &lt;&gt; '' THEN COL3<br> &nbsp;&nbsp;&nbsp;&nbsp;WHEN COL2 &lt;&gt; '' THEN COL2<br> &nbsp;&nbsp;&nbsp;&nbsp;WHEN COL1 &lt;&gt; '' THEN COL1 <br> END AS OUTPUT FROM MYTABLE;</p> <p>&nbsp;</p> 2011-06-02T06:45:09-04:00