ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Select specific column based on another column value in SQL Server<p>Hey <a class="username" rel="makumbi"> makumbi</a>,</p> <p>Please refer below sample query</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @TestDemo AS TABLE(Fatherphone VARCHAR(20),MotherPhone VARCHAR(20),FFromdate VARCHAR(20),FTos VARCHAR(20),Mfrom VARCHAR(20),Mdate VARCHAR(20)) INSERT INTO @TestDemo VALUES(&#39;0782911364&#39;,&#39;0782911364&#39;,&#39;01-02-2017&#39;,&#39;02-02-2017&#39;,&#39;03-02-2018&#39;,&#39;02-02-2018&#39;) INSERT INTO @TestDemo VALUES(&#39;0782911363&#39;,&#39;0782911363&#39;,&#39;01-02-2017&#39;,&#39;02-02-2017&#39;,&#39;03-02-2018&#39;,&#39;02-02-2018&#39;) DECLARE @phone VARCHAR(20) SET @phone=&#39;0782911363&#39; IF EXISTS(SELECT * FROM @TestDemo WHERE Fatherphone = @phone) BEGIN SELECT Fatherphone,FFromdate,FTos FROM @TestDemo WHERE Fatherphone = @phone END ELSE BEGIN SELECT MotherPhone,Mfrom,Mdate FROM @TestDemo WHERE MotherPhone = @phone END</pre> <p><span style="text-decoration: underline;"><strong>Output</strong></span></p> <table border="1"> <tbody> <tr> <td><strong>Fatherphone</strong></td> <td><strong>FFromdate</strong></td> <td><strong>FTos</strong></td> </tr> <tr> <td>782911363</td> <td>1/2/2017</td> <td>2/2/2017</td> </tr> </tbody> </table> <p>&nbsp;</p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/755062/Select-specific-column-based-on-another-column-value-in-SQL-Server/https://www.aspforums.net:443/Threads/755062/Select-specific-column-based-on-another-column-value-in-SQL-Server/Mon, 31 Dec 2018 00:50:57 GMT