Solved

SQL WHERE sub clause

Posted on 2008-06-22
4
842 Views
Last Modified: 2012-05-05
I need to run the statement below but I am receiving the following error message:

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

I know what the error is telling me (iti s returning more than one ponumber for the query).  I need to know how I would run that and show me all ponumber that match the where clause.

Any ideas?
select a.ponumber, a.itemnmbr, a.itemdesc, a.vendorid, a.unitcost, b.stndcost, b.currcost from 

(select * from pop10110) A

left join 

(select * from iv00101) B

on a.itemnmbr = b.itemnmbr

where (a.unitcost > b.stndcost) or (a.unitcost = 0) and (ponumber=(select ponumber from pop10100 where postatus = '5'))

order by ponumber asc

Open in new window

0
Comment
Question by:r270ba
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
frankytee earned 500 total points
Comment Utility
you have = select rather than IN select, try:
select a.ponumber, a.itemnmbr, a.itemdesc, a.vendorid, a.unitcost, b.stndcost, b.currcost from
(select * from pop10110) A
left join
(select * from iv00101) B
on a.itemnmbr = b.itemnmbr
where (a.unitcost > b.stndcost) or (a.unitcost = 0) and (ponumber IN (select ponumber from pop10100 where postatus = '5'))
order by ponumber asc
0
 
LVL 13

Expert Comment

by:bglodde
Comment Utility
select a.ponumber, a.itemnmbr, a.itemdesc, a.vendorid, a.unitcost, b.stndcost, b.currcost from
(select * from pop10110) A
left join
(select * from iv00101) B
on a.itemnmbr = b.itemnmbr
where (a.unitcost > b.stndcost) or (a.unitcost = 0) and (ponumber IN(select ponumber from pop10100 where postatus = '5'))
order by ponumber asc
0
 

Author Comment

by:r270ba
Comment Utility
Could I split the points with the two answers since they were both correct and one posted as I was assigning points?
0
 
LVL 13

Expert Comment

by:bglodde
Comment Utility
I was just a little too slow! :)
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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now