n2dweb
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
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))