473,837 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I am getting 2 resultsets depending on conditon, In the second
conditon i am getting the above error could anyone help me..........
CREATE proc sp_count_AllNew sPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@Cus tomerId )
if not exists(select CustomerId from NewsDelivery where
NewsPapersId=@N ewsId)

begin
select count( NewsPapersId) from NewsPapers
end
if exists(select CustomerId from NewsDelivery where
NewsPapersId=@N ewsId)

begin
select count(NewsDelId ) from NewsDelivery where
Customerid=@Cus tomerid

end
GO
Jul 20 '05 #1
3 31442
On 20 Apr 2004 08:26:03 -0700, Nachi wrote:
I am getting 2 resultsets depending on conditon, In the second
conditon i am getting the above error could anyone help me..........
CREATE proc sp_count_AllNew sPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@Cu stomerId )
if not exists(select CustomerId from NewsDelivery where
NewsPapersId=@ NewsId)

begin
select count( NewsPapersId) from NewsPapers
end
if exists(select CustomerId from NewsDelivery where
NewsPapersId=@ NewsId)

begin
select count(NewsDelId ) from NewsDelivery where
Customerid=@Cu stomerid

end
GO


This is the cause of your problem:

set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@Cus tomerId )

There are apparently at least two rows in NewsDelivery that satisfy
the condition CustomerId = @CustomerID. The value for @NewsID can only
be taken from one of these rows, but which one? You didn't tell SQL
Server how to choose, so SQL Server throws an error message.

Apart from this, I fail to see the logic of what you're doing, but I
think it can be done simpler. Can you explain what you try to achieve?

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
Hugo Kornelis <hugo@pe_NO_rFa ct.in_SPAM_fo> wrote in message news:<a4******* *************** **********@4ax. com>...
On 20 Apr 2004 08:26:03 -0700, Nachi wrote:
I am getting 2 resultsets depending on conditon, In the second
conditon i am getting the above error could anyone help me..........
CREATE proc sp_count_AllNew sPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@Cu stomerId )
if not exists(select CustomerId from NewsDelivery where
NewsPapersId=@ NewsId)

begin
select count( NewsPapersId) from NewsPapers
end
if exists(select CustomerId from NewsDelivery where
NewsPapersId=@ NewsId)

begin
select count(NewsDelId ) from NewsDelivery where
Customerid=@Cu stomerid

end
GO


This is the cause of your problem:

set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@Cus tomerId )

There are apparently at least two rows in NewsDelivery that satisfy
the condition CustomerId = @CustomerID. The value for @NewsID can only
be taken from one of these rows, but which one? You didn't tell SQL
Server how to choose, so SQL Server throws an error message.

Apart from this, I fail to see the logic of what you're doing, but I
think it can be done simpler. Can you explain what you try to achieve?

Best, Hugo


Hi Guys,

Thanks for kind Help....

Infact i have solved the problem by rewriting the procedure

CREATE proc sp_count_AllNew sPapers
@CustomerId int

as
declare @flag int
if exists (select CustomerId from NewsDelivery where CustomerId=@Cus tomerId )
begin
set @flag=0

end
else
begin
set @flag=1
end

if @flag=1
begin
select count( NewsPapersId) from NewsPapers
end

if @flag=0

begin
select count(NewsDelId ) from NewsDelivery where Customerid=@Cus tomerid

end
GO
Jul 20 '05 #3
On 21 Apr 2004 01:06:23 -0700, Nachi wrote:
Infact i have solved the problem by rewriting the procedure

(snip)

Hi Nachi,

Why make it more complex than necessary? The code in David Portas'
first message in this discussion is completely equivalent to your
code, but a lot shorter and easier to maintain.

(David's second suggestion will work as well, but uses some tricks
that not all SQL programmers will be able to understand - this might
make future maintenance more costly)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2061
by: Nachi | last post by:
Hi, Urgent Help appreciated.... I am getting resultset with first condition and when try to get the resutlset from second condition i am getting the above error in SQL200. I know that i am getting more then one value in the second condition but even i am getting more then one value in my first statement
2
3238
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
1
6730
by: cincyn12 | last post by:
Hi, I'm really new to access. (Am only a beginner in SQL) I'm trying to create subqueries similar to SQL+ for a sum using case when within date ranges. (Or Decode by month sum) i.e. Trying to get total shipped qty for customers based on quarters. 10-01-04 through 12-31-04, then 01-01-05 thru 03-31-05... etc Current access table look like:
5
6600
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the following SQL statement. INSERT INTO OrderItems (ClientID, ProductID, OrderHeaderID, Quantity, Dispatched, BackOrdered) SELECT ClientID, ProductID, 1371 AS OrderHeaderID, Quantity, Dispatched, BackOrdered FROM Basket WHERE RequisitionID = 1369 The...
2
1948
by: reap76 | last post by:
I am running the following query: if (select IntExternalAccountID from ExternalAccount) = (select IntExternalAccountID from InternalAccount) select * from InternalAccount where AccountPurpose=2 and getting the following error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. What I am attempting is if the values in ColumnA from...
3
2923
by: Shals | last post by:
Hi, I'm using Form and a subform control within that form. Main form is getting data from one table(Buildings) and subform is getting data from another table(BldgDataByFloor). but both the form and subform are linked through a child field which is common in both the tables(BuildingNumber). Now, whenever I close the form I receive an error "Subquery returned more than 1 value. This is not permitted when the
0
2075
by: kiran2nirvan | last post by:
hi please help in solving this i am recieving this error"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression." for the code CREATE procedure . (@frmMasterID int,
1
2137
by: Sebarry | last post by:
Hi, I'm trying to read the results of a database query into an XML document but it's only read so far and stopping. The XML document is as follows: <?xml version="1.0" encoding="utf-8"?> <night> <name>Poontang</name>
2
1533
by: neilgilbert1234 | last post by:
Hi Everyone, Im sure this is an easyone, im a newbie to anything half complex in sql so any help would be greatly appreaciated. I have one table that has two values, i need to multiply those values and stick the result back into the table. I have used the script below but getting an error: "Subquery returned more than 1 value. This is not permitted when the subquery follows" Script used: update dbo.PCProjectEntry set...
3
11397
by: jideesh | last post by:
---------------trigger code create trigger DeletepurchaseItems on table_purchaseitems for delete,update as begin select * from deleted update table_STOCK set ostock=(ostock-(select sqty from deleted)) where itemcode=(select itemcode from deleted)and coid=(select compid from deleted) and fycode=(select financialyear from deleted) end
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9685
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10580
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10277
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.