Link to home
Start Free TrialLog in
Avatar of n2dweb
n2dwebFlag for United States of America

asked on

Conditional SQL Update from another table

Conditional SQL Update from another table
 I need to update eStatus.NewL1 with the value of eLookup.L1
if (eStatus.Desc = eLookup.Desc) AND (eStatus.HomeLabor1 = eLookup.L1H)
ELSE (eStatus.Desc = eLookup.Desc) AND (eLookup.LHome IsNull)

Table eStatus
EmpKey Desc      HomeLabor1      NewL1
1                 T                    X
2                 T                    Y
3                 T                    Z
4                 U                    P

Table eLookup
Desc      L1H         L1
T                                V
T                A              D
T                X              E
T                Y              E
U               K
U                R            R

So the results should be:
Table eStatus

EmpKey Desc      HomeLabor1      NewL1
1                 T                    X                   E
2                 T                    Y                   E
3                 T                    Z                   V
4                 U                    P                   K


Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Something like:

UPDATE [eStatus]
    SET [NewL1] = [L1]
    FROM eLookup                    
INNER JOIN eStatus ON eStatus.Desc = eLookup.Desc) AND ((eStatus.HomeLabor1 = eLookup.L1H)
                      OR (eLookup.LHome Is Null))
Avatar of n2dweb

ASKER

Thanks!