Hello Friends,
When ever some one ask question like that how to insert data from one table to another our mind strikes and give answer that create one cursor which will access all data from one table and insert in to anothre table.sorry friends i give some nice solution then right now you have.
First Method to do such kind of stuff.
This method is used when table is already created in the database earlier and data is to be inserted into this table from another table.
First table which is allready created name is test_from.
Create New Table which have Name test_to.
CREATE TABLE test_to (FirstName VARCHAR(100), LastName VARCHAR(100))
INSERT INTO test_to (FirstName, LastName)
SELECT FirstName, LastName FROM test_from WHERE id = 2
Second Method
This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.
SELECT FirstName, LastName INTO test_to FROM test_from WHERE id = 2
Enjoy Friends.
Tags: Insert Data From One Table to Another Table in Sql Serv, INSERT INTO SELECT, SELECT INTO TABLE
Hello ! I am Arjun Jadeja a Software Engineer by Profession. You can contribute and I will distribute your ideas through this site. Thanks and Enjoy
One comment
Leave a reply