473,401 Members | 2,125 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,401 software developers and data experts.

Subquery returned more than 1 value. This is not permitted when the subquery...

I have a stored procedure that calls another stored procedure on a different server. I get the error i wrote above. The first procedure is:
Expand|Select|Wrap|Line Numbers
  1. set @DB_NAME = (select db_name from all_servers where server_no = @server_no)
  2. set @SERVER_ADDRESS = (select server_address from all_servers where server_no = @server_no)
  3. DECLARE @exec_statement varchar (100)
  4. select @exec_statement = '[' + @SERVER_ADDRESS + '].' + @DB_NAME + 'dbo.DeleteUsers'
  5. exec @exec_statement
the second procedure
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDERE [dbo].[DeleteUsers] AS
  2. DELETE FROM all_accounts
  3. WHERE userid in (SELECT userid FROM dbo.temp_accounts)
im completely sure that the problem doesn't occur because of the first 2 selects (the db_name and server_address), so it must be the second procedure, but the second procedure *should* return more then one row (for that i use 'in' instead of '=')! how is this possible?
Mar 26 '08 #1
7 1749
ck9663
2,878 Expert 2GB
I have a stored procedure that calls another stored procedure on a different server. I get the error i wrote above. The first procedure is:
Expand|Select|Wrap|Line Numbers
  1. set @DB_NAME = (select db_name from all_servers where server_no = @server_no)
  2. set @SERVER_ADDRESS = (select server_address from all_servers where server_no = @server_no)
  3. DECLARE @exec_statement varchar (100)
  4. select @exec_statement = '[' + @SERVER_ADDRESS + '].' + @DB_NAME + 'dbo.DeleteUsers'
  5. exec @exec_statement
the second procedure
Expand|Select|Wrap|Line Numbers
  1. ALTER PROCEDERE [dbo].[DeleteUsers] AS
  2. DELETE FROM all_accounts
  3. WHERE userid in (SELECT userid FROM dbo.temp_accounts)
im completely sure that the problem doesn't occur because of the first 2 selects (the db_name and server_address), so it must be the second procedure, but the second procedure *should* return more then one row (for that i use 'in' instead of '=')! how is this possible?

Try isolation:

Run these first and see if there's an error:

Expand|Select|Wrap|Line Numbers
  1. set @DB_NAME = (select db_name from all_servers where server_no = @server_no)
  2. set @SERVER_ADDRESS = (select server_address from all_servers where server_no = @server_no)
  3. select @dbname, @server_address
  4.  
Then run this
Expand|Select|Wrap|Line Numbers
  1. DECLARE @exec_statement varchar (100)
  2. select @exec_statement = '[' + @SERVER_ADDRESS + '].' + @DB_NAME + 'dbo.DeleteUsers'
  3. exec @exec_statement
However, instead of those variables, try and pass the hardcoded value of those variables. You can get it from the select statement you first ran.

It will tell you where the error is.

-- CK
Mar 26 '08 #2
Try isolation:

Run these first and see if there's an error:

Expand|Select|Wrap|Line Numbers
  1. set @DB_NAME = (select db_name from all_servers where server_no = @server_no)
  2. set @SERVER_ADDRESS = (select server_address from all_servers where server_no = @server_no)
  3. select @dbname, @server_address
  4.  
Then run this
Expand|Select|Wrap|Line Numbers
  1. DECLARE @exec_statement varchar (100)
  2. select @exec_statement = '[' + @SERVER_ADDRESS + '].' + @DB_NAME + 'dbo.DeleteUsers'
  3. exec @exec_statement
However, instead of those variables, try and pass the hardcoded value of those variables. You can get it from the select statement you first ran.

It will tell you where the error is.

-- CK
the problem is not in these variables. even if i use select max(db_name) i get the problem. i realy think its the second procedure.
Mar 26 '08 #3
deepuv04
227 Expert 100+
the problem is not in these variables. even if i use select max(db_name) i get the problem. i realy think its the second procedure.
hi,
I think the following statement is returning more than one vlaue

Expand|Select|Wrap|Line Numbers
  1.  
  2. select db_name from all_servers where server_no = @server_no
  3.  
  4. or
  5.  
  6. select server_address from all_servers where server_no = @server_no
  7.  
  8.  
execute these two statements alone and see how many rows it is returning

thanks
Mar 26 '08 #4
ck9663
2,878 Expert 2GB
"Egsakli" what am trying to suggest ;)

-- CK
Mar 26 '08 #5
I said its not these two selects. I tried to execute the program wih hard-coded values ot use the 'max' aggregate but i still get this error.
Mar 26 '08 #6
ck9663
2,878 Expert 2GB
Then execute this with hard coded values for @server_address and @dbname
Expand|Select|Wrap|Line Numbers
  1.       DECLARE @exec_statement varchar (100)
  2.       select @exec_statement = '[' + @SERVER_ADDRESS + '].' + @DB_NAME + 'dbo.DeleteUsers'
  3.       exec @exec_statement
-- CK
Mar 26 '08 #7
deepuv04
227 Expert 100+
hi,
I think the following statement is returning more than one vlaue

Expand|Select|Wrap|Line Numbers
  1.  
  2. select db_name from all_servers where server_no = @server_no
  3.  
  4. or
  5.  
  6. select server_address from all_servers where server_no = @server_no
  7.  
  8.  
execute these two statements alone and see how many rows it is returning

thanks
Hi,
Did you tried the above code...?

okey change the statements in your procedure to: (just replace SET to SELECT and try )

Expand|Select|Wrap|Line Numbers
  1.  
  2.       select @DB_NAME = (select db_name from all_servers where server_no = @server_no)
  3.  
  4.       select @SERVER_ADDRESS = (select server_address from all_servers where server_no = @server_no)
  5.  
  6.  
and try ...
Mar 27 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: leegold2 | last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in the subquery below because of the subquery's error message. I thought w/"IN" I'd get three (3) records returned as expected....
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...
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...
0
by: abednegoo | last post by:
Hi All, I tried to find the solution for my problem, but i couldn't find it. If my problem is already solved somewhere, please provide me the link... I'm not a developer myself, but the...
1
by: Aleck | last post by:
Hie. I have a trigger that monitors changes to my table fields but I get an error saying subquery returned more than one value.Below is the code for my trigger, hope you will figure out whats...
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...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.