Wednesday, March 7, 2012

Importing data from another table

Hi All,

I'm coming from using MySQL, and in their dialect you could pull data from one table to another using the following:


INSERTINTO Table1 (fname, lname)
VALUES(
SELECTfname, lname
FROMTable2
)

Let's assume Table1 is a simple table with the fields ID (PK/Identity), fname, and lname. This query would grab all the first and last names out of Table2 (fname and lname fields) and insert them into Table1, generating the ID for each new row.

How would I do this in T-SQL?

INSERTINTO Table1
SELECT fname, lname
FROMTable2

Limno

No comments:

Post a Comment