Solved

Update statement getting error "Subquery returned more than 1 value"

Posted on 2007-03-22
6
361 Views
Last Modified: 2007-03-22
Hello, I need to update a field in a table with data from another table and am getting an error. What's wrong with my statement?

Update #TempMyQuotes
set SOPNumber = (Select b.SOPNumber
from BB_OrderHeader b, #TempMyQuotes a
Where a.QuoteNumber = b.QuoteNumber)


Error Message:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

0
Comment
Question by:gogetsome
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18772085
your subquery is returning more than one values


Update #TempMyQuotes
set SOPNumber = (Select MAX(b.SOPNumber)
from BB_OrderHeader b, #TempMyQuotes a
Where a.QuoteNumber = b.QuoteNumber)
0
 

Author Comment

by:gogetsome
ID: 18772142
Thanks for responding Aneeshattingal!
That statement updated all rows with the Max SOPNumber from BB_OrderHeader.

Each row in #TempMyQuotes may or may not have a corresponding row in bb_OrderHeader. The unique key between the two tables is QuoteNumber. If there is a QuoteNumber in #TempMyQuotes  and in bb_OrderHeader I need to update #TempMyQuotes .SOPNumber with the bb_OrderHeader.SOPNumber...
The SOPNumber tells the user that the Quote has been ordered.

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 18772172
Update a
set SOPNumber = MAX(b.SOPNumber)
from BB_OrderHeader b
INNER JOIN #TempMyQuotes a
ON a.QuoteNumber = b.QuoteNumber

0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

Author Comment

by:gogetsome
ID: 18772173
I think I have to do one update at a time via a looping method?? if so how can I accomplish that?
0
 

Author Comment

by:gogetsome
ID: 18772222
Strike that last comment.

This worked after I remove the max

Update a
set SOPNumber = (b.SOPNumber)
from BB_OrderHeader b
INNER JOIN #TempMyQuotes a
ON a.QuoteNumber = b.QuoteNumber
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18772287
oops, i forgot to remove that MAX() part :( ....
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

680 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