Further to Solution 1 I thought a couple of examples might help ...
Scenario 1:
All of the columns I need for TableA are in TableB
- I only need some of the rows
- but TableB has more columns than TableA
- And they have different names!
Example of Insert:
INSERT INTO TableA (SELECT Col1, Col3, Col7 FROM TableB WHERE RecType = 2)
Scenario 2:
Similar to 1 above but one column in TableA needs to be set to a specific value depending on a value in column RecType ...
INSERT INTO TableA (SELECT Col1, Col3,
CASE WHEN RecType IN (1,3,4) THEN 'Morgen'
WHEN RecType = 5 THEN 'Tag'
ELSE 'Abend' END
FROM TableB)
Scenario 3:
Some columns I need are TableB AND TableC
- but I already have data in TableA and I just want to update the rows
UPDATE A
SET AColumnX = B.ColX, AColumnY = C.ColY
FROM TableA AS A
INNER JOIN TableB AS B ON A.PKey = B.FKtoA
INNER JOIN TableC AS C ON B.PKey = C.FKtoA
There are lots of different scenarios that could arise I just thought that a taster might help.