Previous Article
SQL Server, get the SUM of all values in a table, and add it to another tables values
SQL Server Insert into Table from another table in the same database
Next Article
SQL Server Insert into one table, from another table in another database
Coding Article #: 79 - Published On: July 06, 2017 @ 17:51:39 PM - Last Updated on: July 06, 2017
This article has been Favorited 0 times
Join today, and add this to your favorites.
Coding Source - Share on MySpace Coding Source - Share With Facebook Coding Source - Share on Twitter Coding Source - Share on Reddit Coding Source - Share on Digg It Coding Source - Share on Stumble Upon It Coding Source - Share on Delicious
Share With Friends (Updated 6-8-2010)

Supported Files
No Files for this Article.
No Screenshot Available
Using this simple statement, you will be able to grab records from another table and insert them records into another table, within the same database.

In this example, we have 2 tables with the same column names, ColOne and ColTwo.
We are taking the values from TableOne and inserting (Copying) the records over to TableTwo.

insert into TableTwo (ColOne, ColTwo) select ColOne, ColTwo from TableOne


You can use this statement in a SQL Query Statement in ASP Classic, and ASP.NET as well.

ASP classic.

<%
        Set sql= Server.CreateObject("ADODB.Command")
        sql.ActiveConnection=CFFDConn
        sql.Prepared = true
        sql.commandtext="insert into TableTwo (ColOne, ColTwo) select ColOne, ColTwo from TableOne"
        sql.execute
%>


ASP.NET (VB)

<%
        strSQL = "insert into TableTwo (ColOne, ColTwo) select ColOne, ColTwo from TableOne"
        objCmd = New OleDbCommand(strSQL, dbconn)
        objCmd.ExecuteNonQuery()
%>
Post to Facebook about: SQL Server Insert into Table from another table in the same database