ErocM
ErocM

Reputation: 4662

Need to populate a column based on another column in another table

I'm probably overthinking this so here goes.

I have two tables. The first one I want to populate the CorporationId based off it's TokenId value.

dbo.UsersAccountLink:

enter image description here

And the table that I want to get the value from:

Company.Token:

enter image description here

Here is what I have but it's not set right so it will not run. I'm not sure how to do this:

INSERT INTO dbo.UsersAccountLink.CorporationId
Select CorporationId 
From Company.Token
Where Company.Token.TokenId = dbo.UsersAccountLink.TokenId

I want to populate dbo.UsersAccountLink.CorporationId with the value in Company.Token.CorporationId based on the TokenId.

Help?!

Upvotes: 3

Views: 4251

Answers (1)

S3S
S3S

Reputation: 25152

Looks like you want to update versus insert...

update dbo.UsersAccountLink
set CorporationID = 
(Select CorporationId 
From Company.Token
Where Company.Token.TokenId = dbo.UsersAccountLink.TokenId)

Upvotes: 4

Related Questions