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.Merge Rows having NULL values in SQL Server<p>Hi&nbsp;iammann,</p> <p>Refer the below test query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">DECLARE @Test AS TABLE(Name VARCHAR(50),[Term-I] CHAR(1),[Term-II] CHAR(1),orderno INT) INSERT INTO @Test VALUES(&#39;Art Education&#39;,&#39;B&#39;,NULL,14) INSERT INTO @Test VALUES(&#39;Computer Application&#39;,NULL,&#39;E&#39;,4) INSERT INTO @Test VALUES(&#39;Computer Application&#39;,&#39;A&#39;,NULL,4) INSERT INTO @Test VALUES(&#39;Health &amp; Physical Education&#39;,&#39;C&#39;,NULL,15) INSERT INTO @Test VALUES(&#39;Work Education&#39;,&#39;D&#39;,NULL,16) SELECT Name,ISNULL(MAX([Term-I]),&#39;&#39;)[Term-I],ISNULL(MAX([Term-II]),&#39;&#39;)[Term-II],orderno FROM @Test GROUP BY Name,orderno ORDER BY Name</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr align="center"> <td><strong>Name</strong></td> <td><strong>Term-I</strong></td> <td><strong>Term-II</strong></td> <td><strong>orderno</strong></td> </tr> <tr> <td>Art Education</td> <td>B</td> <td>&nbsp;</td> <td>14</td> </tr> <tr> <td>Computer Application</td> <td>A</td> <td>E</td> <td>4</td> </tr> <tr> <td>Health &amp; Physical Education</td> <td>C</td> <td>&nbsp;</td> <td>15</td> </tr> <tr> <td>Work Education</td> <td>D</td> <td>&nbsp;</td> <td>16</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/272381/Merge-Rows-having-NULL-values-in-SQL-Server/https://www.aspforums.net:443/Threads/272381/Merge-Rows-having-NULL-values-in-SQL-Server/Thu, 15 Nov 2018 00:41:57 GMT