Solved

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

Posted on 2014-12-05
2
106 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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

13 Experts available now in Live!

Get 1:1 Help Now