Solved

Update, Set, and Select

Posted on 2003-10-24
4
8,368 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á
ID: 9625117
I think that there are more dlycsh.site_no (GROUP BY dlycsh.site_no) than one there.
0
 
LVL 2

Expert Comment

by:renuraj
ID: 9635131
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
ID: 9654255

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
ID: 10587210
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
activemq cluster 1 239
ColdFusion Application log reports a 'Java heap space' error 6 316
method reurn 7 85
Protect jar file - windows app 2 65
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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