Solved

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

Posted on 2007-03-22
6
356 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

708 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

11 Experts available now in Live!

Get 1:1 Help Now