If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Subquery returned more than 1 value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-11, 03:23
dhanooz dhanooz is offline
Registered User
 
Join Date: Dec 2011
Posts: 3
Smile Subquery returned more than 1 value

iam getting the below error while trying to run sql query

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.

but if in the same below query if i put the parameter in upto 10 then its working fine......if the parameter is 11 or above then the query is giving the above error....pls help me


SELECT substring(sc.container_id,0,14) container_id,
imc.item_class,
sh.ship_to, sh.shipment_id,
cust.ADDRESS1,
sh.carrier,
sh.stop_sequence,
sh.company,
sh.order_type
FROM (SELECT max (im.item_class) item_class
FROM shipping_container sc WITH (NOLOCK), item im WITH (NOLOCK)
WHERE sc.item = im.item
AND sc.parent =
(SELECT internal_container_num
FROM shipping_container WITH (NOLOCK)
WHERE sc.container_id = 'RP111027073'
AND internal_shipment_line_num IS NULL)) imc,
shipping_container sc WITH (NOLOCK),
shipment_header sh WITH (NOLOCK),
( select customer, address1, company from dbo.CUSTOMER ) cust
WHERE sc.container_id= 'RP111027073 '
AND sc.internal_shipment_line_num IS NULL
AND sh.internal_shipment_num = sc.internal_shipment_num
and sh.ship_to = cust.customer
and sh.company = cust.company
Reply With Quote
  #2 (permalink)  
Old 12-08-11, 03:23
aflorin27 aflorin27 is offline
Registered User
 
Join Date: Apr 2008
Location: Iasi, Romania
Posts: 317
1. your question isn't related to the original question of this thread
2. the error message is self-explanatory: one of your sub-SELECT returns more than 1 row.
__________________
Florin Aparaschivei
Iasi, Romania
Reply With Quote
  #3 (permalink)  
Old 12-08-11, 09:25
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
I split these posts off into their own thread, the original post was tacked onto an unrelated thread.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 12-08-11, 11:33
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
Try this:
Code:
SELECT substring(sc.container_id,0,14) container_id,
	imc.item_class,
	sh.ship_to, sh.shipment_id,
	cust.ADDRESS1,
	sh.carrier,
	sh.stop_sequence,
	sh.company,
	sh.order_type
FROM shipping_container sc WITH (NOLOCK)
	INNER JOIN shipment_header sh WITH (NOLOCK) ON
		sc.internal_shipment_num = sh.internal_shipment_num
	INNER JOIN dbo.CUSTOMER AS cust ON
		sh.ship_to = cust.customer
		and sh.company = cust.company
	CROSS JOIN 
		(SELECT max(im.item_class) item_class
		FROM shipping_container sc WITH (NOLOCK)
			INNER JOIN item im WITH (NOLOCK) ON
				sc.item = im.item
		WHERE sc.container_id = 'RP111027073'
			AND internal_shipment_line_num IS NULL
		) imc
WHERE sc.container_id= 'RP111027073 '
	AND sc.internal_shipment_line_num IS NULL
The query could be simplified a great deal.
Like ( select customer, address1, company from dbo.CUSTOMER ) cust
I couldn't think of any reason why it was there.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On