Solved

MS SQL - Need to update a column in one table based off of a left outer join

Posted on 2014-12-05
2
111 Views
Last Modified: 2014-12-05
Below is a query I run to find data from two tables.   There is a nchar(10) column in the IMFiledata table called "imported" that I want to update with "Yes" when the query finds records that match but I've been unsuccessful in working an update clause into the query.  

select A.Custbox, A.tempid, A.DEPT, A.boxtype,
       B.CLIENT_NBR, B.MATTER_DESC, B.CLIENT_NAME, B.LAWYER_1, B.MATTER_NBR, B.CLOSE_DATE
from NDXData A
left outer join IMFiledata B on A.CustBox =B.skpboxnbr
where A.Custbox <> '' and b.FILE_STATUS <>'OUT' and A.DEPT <>''

Any ideas?

Thanks.
0
Comment
Question by:RavenTim
[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
2 Comments
 
LVL 10

Accepted Solution

by:
Walter Padrón earned 500 total points
ID: 40483500
If you use an left outer join you includes the non-matching rows too

UPDATE IMFiledata 
SET imported= 'YES'
FROM 
(
    select A.Custbox, A.tempid, A.DEPT, A.boxtype,
           B.CLIENT_NBR, B.MATTER_DESC, B.CLIENT_NAME, B.LAWYER_1, B.MATTER_NBR, B.CLOSE_DATE
    from NDXData A
    join IMFiledata B on A.CustBox =B.skpboxnbr
    where A.Custbox <> '' and b.FILE_STATUS <>'OUT' and A.DEPT <>''
) AS C
JOIN IMFileData D ON C.skpboxnbr = D.skpboxnbr

Open in new window

0
 

Author Closing Comment

by:RavenTim
ID: 40483706
Thanks Walter!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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