Thursday, February 12, 2009

Update and Insert data in one table with data from another table

-- To Update data from one table to another table

UPDATE TABLEA

SET b = TABLEB.b1,
c = TABLEB.c1,
d = TABLEB.d1
FROM TABLEA, TABLEB
WHERE TABLEA.a = TABLEB.a1
AND TABLEB.e1 > 40


-- To Insert data from one table to another table
INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion =
2