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.Insert Stored Procedure result to Temporary Table and Merge NULL value rows in SQL Server<p>Hi&nbsp;smile,</p> <p>Create a stored procedure of your dynamic query and then insert the stored procedure result to a temp table.</p> <p><a href="https://blog.sqlauthority.com/2013/05/27/sql-server-how-to-insert-data-from-stored-procedure-to-table-2-different-methods/">https://blog.sqlauthority.com/2013/05/27/sql-server-how-to-insert-data-from-stored-procedure-to-table-2-different-methods/</a></p> <p>Then from the temptable merge the&nbsp;rows having null values.</p> <h1 class="header"><a class="title f16" href="https://www.aspforums.net/Threads/272381/Merge-Rows-having-NULL-values-in-SQL-Server/">Merge Rows having NULL values in SQL Server</a></h1> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/273252/Insert-Stored-Procedure-result-to-Temporary-Table-and-Merge-NULL-value-rows-in-SQL-Server/https://www.aspforums.net:443/Threads/273252/Insert-Stored-Procedure-result-to-Temporary-Table-and-Merge-NULL-value-rows-in-SQL-Server/Wed, 05 Dec 2018 03:50:00 GMTInsert Stored Procedure result to Temporary Table and Merge NULL value rows in SQL Server<p>Hi&nbsp;smile,</p> <p>Create a stored procedure of your dynamic query which will return all the result having null rows.</p> <p>Then create a Temp table and insert the stored procedure result set to the temp table and use select query to&nbsp;merge the null rows.</p> <p>Check the below example.&nbsp;</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">CREATE PROCEDURE TempDetails AS BEGIN DECLARE @Temp AS TABLE(AdmissionNo VARCHAR(10),[Eng/Urdu(W/Re/Dic)] INT,[Com/ISL(W/RE/Dic)] INT,Total INT,Percentage INT) INSERT INTO @Temp VALUES(&#39;R-1&#39;,NULL,70,120,60) INSERT INTO @Temp VALUES(&#39;R-1&#39;,50,NULL,120,60) INSERT INTO @Temp VALUES(&#39;R-2&#39;,NULL,50,100,50) INSERT INTO @Temp VALUES(&#39;R-2&#39;,50,NULL,100,50) INSERT INTO @Temp VALUES(&#39;R-3&#39;,NULL,45,90,45) INSERT INTO @Temp VALUES(&#39;R-3&#39;,45,NULL,90,45) SELECT * FROM @Temp END CREATE TABLE #Temp(AdmissionNo VARCHAR(10),[Eng/Urdu(W/Re/Dic)] INT,[Com/ISL(W/RE/Dic)] INT,Total INT,Percentage INT) INSERT INTO #Temp EXEC TempDetails SELECT AdmissionNo,MAX([Eng/Urdu(W/Re/Dic)]) [Eng/Urdu(W/Re/Dic)],MAX([Com/ISL(W/RE/Dic)]) [Com/ISL(W/RE/Dic)],MAX(Total) Total,MAX(Percentage) Percentage FROM #Temp GROUP BY AdmissionNo DROP TABLE #Temp</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr> <td><strong>AdmissionNo</strong></td> <td><strong>Eng/Urdu(W/Re/Dic)</strong></td> <td><strong>Com/ISL(W/RE/Dic)</strong></td> <td><strong>Total</strong></td> <td><strong>Percentage</strong></td> </tr> <tr> <td>R-1</td> <td>50</td> <td>70</td> <td>120</td> <td>60</td> </tr> <tr> <td>R-2</td> <td>50</td> <td>50</td> <td>100</td> <td>50</td> </tr> <tr> <td>R-3</td> <td>45</td> <td>45</td> <td>90</td> <td>45</td> </tr> </tbody> </table> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/273252/Insert-Stored-Procedure-result-to-Temporary-Table-and-Merge-NULL-value-rows-in-SQL-Server/https://www.aspforums.net:443/Threads/273252/Insert-Stored-Procedure-result-to-Temporary-Table-and-Merge-NULL-value-rows-in-SQL-Server/Thu, 06 Dec 2018 00:37:01 GMT