Thursday, August 12, 2010

A delicious copy from table to table in SQL SERVER (2008)

What are we cooking today?
Copy from a table1 into a table2
Copy from the result set from a stored procedure into an existing table2
Copy from table1 into a table2 that does not exist yet (to be created)

Recipe

---When the Table2 (target table) was previously created.
INSERT INTO Table2 (fname, lname)
SELECT fname, lname
FROM Table1

---When the Table2 (target table) was previously created. [From an stored procedure]
INSERT INTO Table2 (fname, lname)
exec spGetInfo


---When the table2 (target table) WAS NOT created.
SELECT fname, lname
INTO Table2
FROM Table1


Enjoy it!

No comments:

Post a Comment