Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Update

Status
Not open for further replies.

TitleistDBA

IS-IT--Management
Apr 22, 2002
162
US
I get the following error on this update.

Error: SQL0811 - Result of SELECT more than one row.

update mvxcjdttst.opricl l
set l.OMFMID = (select s.odfmid
from mvxcjdttst.oprbas s,mvxcjdttst.opricl l
where l.omcono = s.odcono
and l.omitno = s.oditno
and s.odfmid <> ' '
)
Can anybody help with this?

 
Hi TitleistDBA,
It is clear that the SELECT inside the UPDATE is retrieving multiple rows.
If that is the case, then you can modify your sql as below:
update mvxcjdttst.opricl l
set l.OMFMID = (select s.odfmid
from mvxcjdttst.oprbas s,mvxcjdttst.opricl l
where l.omcono = s.odcono
and l.omitno = s.oditno
and s.odfmid <> ' ' fetch first 1 rows only
)
Verify the logic of having multiple rows with your SELECT statement.
Hope this helps
Good luck


 
I am making some progress. I changed my update statement to the one belowe. Now I get an error stating the field I am updating does not allow NULLs. so I added and is not null clause but that didn't work!?

update mvxcjdttst.opricl l
set l.OMFMID = (select s.odfmid
from mvxcjdttst.oprbas s
where l.omcono = s.odcono
and l.omitno = s.oditno
and s.odfmid <> ' '
and s.odfmid is not null
)

 
I'm getting closer but now I am back to my first error message. whith this query. It needs to update 467 rows in the opricl table based on that select criteria.


update mvxcjdttst.opricl l
set l.OMFMID = (select s.odfmid
from mvxcjdttst.oprbas s
where l.omcono = s.odcono
and l.omitno = s.oditno
and s.odfmid <> ' ')
WHERE EXISTS (SELECT *
FROM mvxcjdttst.oprbas s
WHERE l.omcono = s.odcono
and l.omitno = s.oditno
and s.odfmid <> ' ')


 
Sorry about coming to this late, particularly as you think that you have solved it. It looks that you wanted a correlated update query along the lines of:
Code:
UPDATE MVXCJDTTST.OPRICL L
 SET OMFMID = (SELECT S.ODFMID
               FROM MVXCJDTTST.OPRBAS S
               WHERE S.ODCONO = L.OMCONO
               AND   S.ODITNO = L.OMITNO
               AND   S.ODFMID <> ' '
              )

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top