-1

Database A has table named table1 and database B has table named table2. Both table have same structure. I need to update B Database table table2 with data from A database table table1 with rows having column5 = true

So far I have tried this but its not working

UPDATE B.dbo.table2
SET table2Id = A_table1.table2Id
FROM A.dbo.table1 as A_table1
WHERE A_table1.Archive = 1
aa003
  • 131
  • 3
  • 16
  • possible duplicate of [Updating columns values from another table SQL](http://stackoverflow.com/questions/27760438/updating-columns-values-from-another-table-sql) – Tab Alleman Mar 04 '15 at 13:56

1 Answers1

0

How do rows from Table A relate to Table B? Assuming there is some natural key that links them together try:

UPDATE B
SET table2Id = A_table1.table2Id
FROM A.dbo.table1 as A_table1
inner join B.dbo.table2 as B on A_table1.NaturalKey = B.NaturalKey
WHERE A_table1.Archive = 1

Obviously, NaturalKey is whatever column relates the two tables together.

Bill Gregg
  • 7,067
  • 2
  • 22
  • 39