0

I have a table of values in which I need to take 'n' number of columns and update another table only where the value has changed.

For example, let's say I have DB1.Table1 and DB2.Table2.
Table1 has columns A, B, C, D and E.
Table2 has columns F, G, H and I.

I want the values in B, C and E to populate the values in G, H and I - where A = F and B <> G, C <> H and E <> I.

I have tried using a JOIN and WHERE, but neither seem to work.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
TripWire
  • 71
  • 1
  • 10
  • I want the values in B, C and E to populate the values in G, H and I - where A = F and B <> G, C <> H and E <> I. I should clarify this. If B <> G, OR C <> H, OR E <> I, it will make the update for the relevant field. – TripWire Dec 03 '15 at 17:24
  • Did you prefix your join with the database names like you have listed in the question? For example `SELECT * FROM DB1.Table1 INNER JOIN DB2.Table2 ON Table2. F = Table1.A` – Chizzle Dec 03 '15 at 17:26
  • Since I have to mention the DB name and the table name, I tried using an alias, but I started getting errors with the way I was using it. I wasn't sure how to alias the second table. For example: Select DB1.Tabl1 t1 works fine. But when I need to place the alias in the middle of the JOIN or the nested SELECT, I get an error. – TripWire Dec 03 '15 at 17:29
  • Have you checked out this question? http://stackoverflow.com/questions/15126560/can-i-join-data-from-2-different-db2-databases-like-sql-server-linked-database You will need DB2 Federation turned on for the cross DB joins. In SQL Server you could use a synonym which is the method I prefer, but I'm not sure if there is an equivalent in DB2 – Chizzle Dec 03 '15 at 17:32
  • That seems a little deeper than what I'm trying to do. I will have to find a roundabout way to do it. Thanks. – TripWire Dec 04 '15 at 00:59

0 Answers0