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.Temporary Table in Stored Procedure with Inner Join in SQL Server<p>Hey <a class="username" rel="chetan"> chetan</a>,</p> <p>The role of temporary table is you can create and use temporary tables in a stored procedure, but the temporary table exists only for the duration of the stored procedure that creates it. When the procedure completes, Adaptive Server automatically drops the temporary table.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">CREATE PROCEDURE TestProcedureJoin AS &nbsp; BEGIN &nbsp; CREATE TABLE #Test1(Id INT, Name VARCHAR(20)) &nbsp; INSERT INTO #Test1 VALUES(1, &#39;Mudassar&#39;) &nbsp; INSERT INTO #Test1 VALUES(2, &#39;John&#39;) &nbsp; INSERT INTO #Test1 VALUES(3, &#39;Suzanne&#39;) Create Table #Test2(Id INT, Country VARCHAR(20)) &nbsp; INSERT INTO #Test2 VALUES(1, &#39;India&#39;) &nbsp; INSERT INTO #Test2 VALUES(2, &#39;USA&#39;) &nbsp; INSERT INTO #Test2 VALUES(3, &#39;Russia&#39;) &nbsp; &nbsp; SELECT t1.Id, t1.Name, t2.Country FROM #Test1 t1 INNER JOIN #Test2 t2 ON t1.Id =t2.Id DROP TABLE #Test1 DROP TABLE #Test2 End GO EXEC TestProcedureJoin</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <table border="1" width="192" cellspacing="0" cellpadding="0"><colgroup><col style="width: 48pt;" span="3" width="64" /> </colgroup> <tbody> <tr style="height: 15.0pt;"> <td style="height: 15.0pt; width: 48pt;" width="64" height="20">Id</td> <td style="width: 48pt;" width="64">Name</td> <td style="width: 48pt;" width="64">Country</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" align="right" height="20">1</td> <td>Mudassar</td> <td>India</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" align="right" height="20">2</td> <td>John</td> <td>USA</td> </tr> <tr style="height: 15.0pt;"> <td style="height: 15.0pt;" align="right" height="20">3</td> <td>Suzanne</td> <td>Russia</td> </tr> </tbody> </table>https://www.aspforums.net:443/Threads/116100/Temporary-Table-in-Stored-Procedure-with-Inner-Join-in-SQL-Server/https://www.aspforums.net:443/Threads/116100/Temporary-Table-in-Stored-Procedure-with-Inner-Join-in-SQL-Server/Thu, 07 Feb 2019 00:34:27 GMT