Solved

Conditional SQL Update from another table

Posted on 2010-09-03
3
371 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:n2dweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33594499
this should do:
UPDATE s
   SET s.NewL1 = l.L1
  FROM eStatus s
  JOIN eLookup l
    ON l.Desc = s.Desc
   AND isnull(l.L1H, s.HomeLabor1 ) = s.HomeLabor1   

Open in new window

0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 33594502
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))
0
 
LVL 1

Author Closing Comment

by:n2dweb
ID: 33594518
Thanks!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question