Solved

Sql Server udpate with select query

Posted on 2011-09-28
2
217 Views
Last Modified: 2012-05-12
Hi,

I have the following statement and am getting an error.  I can see why there is an error, but what is the work around.  

So essentially I need to set check =1 when customernumber=realmid and the barcode =the barcode from another table...

Thanks

UPDATE Customer_Info_Barcode_Assay
SET Check1 = 1
WHERE CustomerNumber=@RealmId and Barcode=(SELECT IntuitQboInvoiceId
                                                               FROM dbo.Intuit_Staging_Invoice_w_ID
                                                               GROUP BY RealmId, IntuitQboInvoiceId)
0
Comment
Question by:joygomez
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 36717616
You have nothing to tie the subselect to the parent.  Try something like below.  Try below

UPDATE BA
SET Check1 = 1
from Customer_Info_Barcode_Assay BA
WHERE CustomerNumber=@RealmId
  and exists (SELECT ii.IntuitQboInvoiceId
                         FROM dbo.Intuit_Staging_Invoice_w_ID ii
                         where ii.RealmId = ba.CustomerNumber
                            and ii.IntuitOboInvoiceId = BA.Barcode)
0
 

Author Comment

by:joygomez
ID: 36717681
Great... works good...
Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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