[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Conditional SQL Update from another table

Posted on 2010-09-03
3
Medium Priority
?
381 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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

826 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