akaWizzmaster
akaWizzmaster

Reputation: 103

Semi-Advanced T-SQL

Here is my scenario:

I have 2 current tables (We'll call them DimA and DimB):

DimA has 2 columns (Key, ZipCode)
DimB has 5 columns (FirstName, LastName, Address, ZipCode, Key)

I need to:

 INSERT INTO DimB(Key) VALUES
     (SELECT Column(Key) FROM DimA WHERE dimA.ZipCode = dimB.ZipCode)

What is the absolute best way to go about making this work?

Upvotes: 1

Views: 83

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

It sounds like you want to UPDATE rather than INSERT. Otherwise, the dimA.ZipCode = dimB.ZipCode expression could never be true.

UPDATE b
SET b.Key = a.Key
FROM DimA a
INNER JOIN DimB b on b.ZipCode = a.ZipCode

Upvotes: 2

Related Questions