Solved

SQL WHERE sub clause

Posted on 2008-06-22
4
843 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
ID: 21843250
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
ID: 21843254
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
ID: 21843272
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
ID: 21843285
I was just a little too slow! :)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard 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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

919 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

15 Experts available now in Live!

Get 1:1 Help Now