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 record from multiple tables into another in SQL Server<p>Hi <a class="username" rel="KatieNgoc"> KatieNgoc</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">DECLARE @tableMain AS TABLE(Id INT, Name VARCHAR(20), Country VARCHAR(20),PostalCode INT) DECLARE @table1 AS TABLE(Id INT,ID_P INT) DECLARE @table2 AS TABLE(Name VARCHAR(20),ID_P INT) DECLARE @table3 AS TABLE(Country VARCHAR(20),ID_P INT) DECLARE @table4 AS TABLE(PostalCode INT,ID_P INT) INSERT INTO @table1 VALUES(1,1) INSERT INTO @table1 VALUES(2,2) INSERT INTO @table2 VALUES(&#39;Mudassar Khan&#39;,1) INSERT INTO @table2 VALUES(&#39;John Hammod&#39;,2) INSERT INTO @table3 VALUES(&#39;India&#39;,1) INSERT INTO @table3 VALUES(&#39;USA&#39;,2) INSERT INTO @table4 VALUES(&#39;111111&#39;,1) INSERT INTO @table4 VALUES(&#39;222222&#39;,2) INSERT INTO @tableMain (Id,Name,Country,PostalCode) SELECT Id,Name,Country,PostalCode FROM @table1 t1 INNER JOIN @table2 t2 ON t1.ID_P = t2.ID_P INNER JOIN @table3 t3 ON t1.ID_P = t3.ID_P INNER JOIN @table4 t4 ON t2.ID_P = t4.ID_P SELECT * FROM @tableMain</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/470585/Insert-record-from-multiple-tables-into-another-in-SQL-Server/https://www.aspforums.net:443/Threads/470585/Insert-record-from-multiple-tables-into-another-in-SQL-Server/Fri, 30 Aug 2019 05:11:49 GMT