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.Using IF ELSE inside View in SQL Server<p>Hi&nbsp;Rockstar8,</p> <p>Use CASE statement.</p> <p>Check this below test query. Now please take its reference and correct your query.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">CREATE VIEW vwGetCustomerDetails AS SELECT TOP 15 CustomerID ,ContactName ,CASE Country WHEN &#39;USA&#39; THEN &#39;United States of America&#39; WHEN &#39;UK&#39; THEN &#39;United Kingdom&#39; ELSE Country END &#39;Country&#39; FROM Customers GO SELECT * FROM vwGetCustomerDetails ORDER BY Country DESC</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr> <td><strong>CustomerID</strong></td> <td><strong>ContactName</strong></td> <td><strong>Country</strong></td> </tr> <tr> <td>BONAP</td> <td>Laurence Lebihan&nbsp;</td> <td>United States of America</td> </tr> <tr> <td>BSBEV</td> <td>Victorian Ashworth</td> <td>United Kingdom</td> </tr> <tr> <td>CHOPS</td> <td>Yang Wang</td> <td>Switzerland</td> </tr> <tr> <td>CENTC</td> <td>Francisco Chang</td> <td>Mexico</td> </tr> <tr> <td>BERGS</td> <td>Christina Berglund&nbsp;</td> <td>Italy</td> </tr> <tr> <td>AROUT</td> <td>Thomas Hardy&nbsp;</td> <td>Ireland</td> </tr> <tr> <td>ANATR</td> <td>Ana Trujillo&nbsp;</td> <td>France</td> </tr> <tr> <td>BLAUS</td> <td>Hanna Moos&nbsp;</td> <td>Finland</td> </tr> <tr> <td>BLONP</td> <td>Fr&eacute;d&eacute;rique Citeaux&nbsp;</td> <td>Finland</td> </tr> <tr> <td>BOTTM</td> <td>Elizabeth Lincoln</td> <td>Canada</td> </tr> <tr> <td>COMMI</td> <td>Pedro Afonso</td> <td>Brazil</td> </tr> <tr> <td>ANTON</td> <td>Antonio Moreno&nbsp;</td> <td>Brazil</td> </tr> <tr> <td>ALFKI</td> <td>Maria&nbsp;</td> <td>Austria</td> </tr> <tr> <td>BOLID</td> <td>Mart&iacute;n Sommer&nbsp;</td> <td>Argentina</td> </tr> <tr> <td>CACTU</td> <td>Patricio Simpson</td> <td>Argentina</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/545361/Using-IF-ELSE-inside-View-in-SQL-Server/https://www.aspforums.net:443/Threads/545361/Using-IF-ELSE-inside-View-in-SQL-Server/Mon, 29 Oct 2018 00:30:04 GMT