Solved

Update, Set, and Select

Posted on 2003-10-24
4
8,363 Views
Last Modified: 2013-12-01
Can anyone tell me why this statement is not working.  I keep getting a

ORA-01427: single-row subquery returns more than one row  

error

UPDATE tmp10110191
   SET mnth_sales_amt =
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
           GROUP BY dlycsh.site_no)

Thanks,

jms
0
Comment
Question by:jmsloan
4 Comments
 
LVL 22

Expert Comment

by:Helena Marková
Comment Utility
I think that there are more dlycsh.site_no (GROUP BY dlycsh.site_no) than one there.
0
 
LVL 2

Expert Comment

by:renuraj
Comment Utility
Could you post us the table tmp10110191 structure!

If tmp10110191 table has site_no column, SQL below will do
UPDATE tmp10110191 t
   SET t.mnth_sales_amt =
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
                AND dlycsh.site_no = t.site_no)

Regards,
0
 
LVL 3

Accepted Solution

by:
evedder earned 20 total points
Comment Utility

Your subquery is returning multiple rows, maybe you should test first the subquery alone and see how many rows it retrieves you, if you receive more than one row you have to use an "any" or "all" clause for comparisons

like

UPDATE tmp10110191
   SET mnth_sales_amt > any
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
           GROUP BY dlycsh.site_no)


that is talking about syntax but to make your statement to work properly we need to know the logistic

regards!
0
 

Expert Comment

by:ksrsrao
Comment Utility
hi
u must use where condition after subqry
ex given  below
update bak_party_fa a set add1=(select substr(add1,1,30) from bak_party
where a.party_code=acct_head) where party_code in
(select b.acct_head from bak_party b)
regards
kalaga
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

9 Experts available now in Live!

Get 1:1 Help Now