473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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_AllNewsPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@CustomerId )
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=@Customerid

end
GO
Jul 20 '05 #1
3 31393
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_AllNewsPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@CustomerId )
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=@Customerid

end
GO


This is the cause of your problem:

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

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_rFact.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_AllNewsPapers
@CustomerId int
as
declare @NewsId int
set @NewsId = (select NewsDelId from NewsDelivery where
CustomerId=@CustomerId )
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=@Customerid

end
GO


This is the cause of your problem:

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

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_AllNewsPapers
@CustomerId int

as
declare @flag int
if exists (select CustomerId from NewsDelivery where CustomerId=@CustomerId )
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=@Customerid

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
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...
2
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...
1
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...
5
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...
2
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 ...
3
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...
0
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...
1
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"?> ...
2
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.