jeudi 16 avril 2020

Update fields based on If-Else condition

I have Table A (source) that needs to update Table B (target), depending on a few rules. There is a matching key between both Tables (which is email).

When field check1 equals "Hello" and check2 equals "World" from Table B, then I want to update three fields.

However, if field check1 equals "Hello" and check2 equals "Pineapple" from Table B, then I want to update just one field.

Pseudo code below:

SELECT Name, City, Phone
FROM A

IF B.check1="Hello" AND B.check2="World" THEN
    update B.Name = A.Name, 
    update B.City = A.City,
    update B.Phone = A.Phone

ELSE IF B.check1="Hello" AND B.check2="Pineapple" THEN
    update B.Name = A.Name

ENDIF

INNER JOIN B
ON A.email = B.email

Aucun commentaire:

Enregistrer un commentaire