0

Table A

Org ID  int not null

Org Name varchar

Table B

AccountID int not null

OrgID  int not null

I want to add the AccountID column into Table A from Table B based on the condition

A.Org ID = B.Org.ID

Can anyone help me how to do this?

5
  • have you tried this and seeing any issue? can you paste the code that you tried? Commented Oct 31, 2014 at 16:47
  • I am not sure which one to use like update set commands, merge, inner join ?? Commented Oct 31, 2014 at 16:54
  • you need to use update with join Commented Oct 31, 2014 at 16:55
  • could u please advise the sample query based on the question above? Commented Oct 31, 2014 at 16:57
  • added the answer, you can build on top of this for next time you have to do such updates with joins Commented Oct 31, 2014 at 17:03

1 Answer 1

2
UPDATE A
SET A.AccountID = B.AccountID
FROM TableA A
JOIN TableB B
on A.OrgID = B.OrgID
Sign up to request clarification or add additional context in comments.

9 Comments

I am getting the following error Msg 2705, Level 16, State 4, Line 1 Column names in each table must be unique. Column name 'AccountID' in table 'dbo.Whitespace' is specified more than once. Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "A.AccountID" could not be bound.
@Shiningstar, looks like you already have the accountid column, then just ry the upadate
Now I am getting following error Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "A.AccountID" could not be bound.
@Shiningstar, does the column AccountId exists ? have you tried adding it to correct table?
No..Table A doen't have [AccountID] column. @RADAR
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.