Solved

Conditional SQL Update from another table

Posted on 2010-09-03
3
329 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now