473,670 Members | 2,574 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 31426
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
3210
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
6723
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
6580
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
1936
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
2919
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
2052
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
2124
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
1525
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
11383
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
8466
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
8384
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,...
1
8591
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
8659
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
7412
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2037
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.