?
Solved

Sql Server udpate with select query

Posted on 2011-09-28
2
Medium Priority
?
227 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 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

864 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