Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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