Take the 2-minute tour ×

I have one database which contains two tables:

-October2012_ID which contains two columns:

a) OldId
b) NewId

-BNP which contains two columns also:


I need to update the BNP table by replacing values contained into the two columns IF these values are available in the column OldId located into the table October2012_ID. And if this is the case, I need to update the columns in BNP by the value of NewId.


Update BNP
SET BNP.**BankId**=October2012_Id.NewId
where BNP.**BankId**=October2012_Id.OldId and October2012_Id.**BankId** is not null

And also:

Update BNP
SET BNP.**OrbId**=October2012_Id.NewId
where BNP.**OrbId**=October2012_Id.OldId and October2012_Id.**OrbId** is not null

I'm a noob in SQL, so could you help me please ?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can try to add or between your conditions:

Update BNP
SET BNP.BankId=October2012_Id.NewId
from October2012_Id
  (BNP.BankId=October2012_Id.OldId and October2012_Id.BankId is not null)
  (BNP.OrbId=October2012_Id.OldId and October2012_Id.OrbId is not null)
share|improve this answer
Thank you it works ! –  Razor Oct 10 '12 at 16:52
   SET BNP.OrbId=October2012_Id.NewId
  FROM October2012_Id
  JOIN BNP.OrbId=October2012_Id.OldId  --The default JOIN is INNER. Just shorthand for INNER JOIN
 WHERE October2012_Id.OrbId IS NOT NULL

You just need to specify the table you'd like the values from using the FROM clause and JOIN onto the table you want to update.

share|improve this answer
Thank you for this ! +1 –  Razor Oct 10 '12 at 16:53

Your Answer


