Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the stored procedure:


USE [authentic]
GO
/****** Object:  StoredProcedure [dbo].[sp_getticket]    Script Date: 11/22/2010 12:11:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_getticket]
@memberid varchar(50)=''
AS
BEGIN
select 
  ticketno, 
  subject, 
  message, 
  attachment  
from 
  tbl_ticket_message 
where 
   messageType='Question' and 
   ticketno=(select ticketno from tbl_ticket where memberid=@memberid)
END



But I get a run time error when it is used by the application:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Posted
Updated 21-Nov-10 19:59pm
v2

thank you.My english is not good. :)

this code worked my project...

update Coordinates set deleted=@deleted , lastUpdateDate=@lastUpdateDate where  shapeId IN (select DISTINCT  id from deleted);
 
Share this answer
 
This subquery:

select ticketno from tbl_ticket where memberid=@memberid


is returning more than one value. It must return one value for ticketno=(select ticketno from tbl_ticket where memberid=@memberid) to make sense, otherwise which value should SQL use to check for equality?

You have a few options:

  1. Is it allowed for a member to have > 1 ticket number? If not, you have a problem in your DB design that should be fixed as you are allowing multiple entries. You should re-design the table or (if in a fix situation) put a constraint on the table to prevent this, this would also need a data-cleansing exercise on your existing data.
  2. I'm guessing 1 isn't the case. If so, you have two options: The first is to change the subquery so it only returns one value (e.g. add a missing join condition, or select the first/last. The SQL provided in your post will only return the first ticket for the member in the table, is this correct?). The second is to change you condition to
    SQL
    where
       messageType='Question' and
       ticketno <big>IN</big>(select ticketno from tbl_ticket where memberid=@memberid)

 
Share this answer
 
v2
You should read the error message. It says Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Subquery returned more than 1 value that means this (select ticketno from tbl_ticket where memberid=@memberid) subquery returns more than one value.

This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
It means ticketno=(select ... this expression is not permitted.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900