Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 'Document' (RDOC)

Yefer Bastidas 1 Reputation point
2022-02-16T02:07:29.47+00:00

how to identify the field that brings more than one value? when I run the store procedure I don't see the error

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,786 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,637 questions
{count} votes

7 answers

Sort by: Most helpful
  1. LiHong-MSFT 10,051 Reputation points
    2022-02-18T07:49:36.68+00:00

    Hi @Yefer Bastidas
    Sorry for not checking your code carefully yesterday.And as experts said ,there are indeed some subqueries in your code that may return more than 1 value.
    As you can see from the error message,there are two situations that can cause this error.

    First : when the subquery follows =, !=, <, <= , >, >=

    and I believe you have double checked this situtuation.

    Second : when the subquery is used as an expression

    Please refer to this sample:

    CREATE TABLE #TEST1(ID INT,Column_1 VARCHAR(10));  
    INSERT INTO #TEST1 VALUES(1,'AA') ,(2,'BB');   
    CREATE TABLE #TEST2(ID INT,Column_2 INT);  
    INSERT INTO #TEST2 VALUES(1,100) ,(2,200) ,(3,300);   
    
    --Subquery returned only 1 value.  
    SELECT *,(SELECT Column_2 FROM #TEST2 WHERE Column_2 = 100) AS 'Number'  
    FROM #TEST1;  
    --Subquery returned more than 1 value.  
    SELECT *,(SELECT Column_2 FROM #TEST2 WHERE Column_2 > 100) AS 'Number'  
    FROM #TEST1;  
    

    So you need to check statements such as: SELECT ...,subquery AS alias , ISNULL(subquery, '') in your code,.

    Best Regards,
    LiHong

    0 comments No comments

  2. Yefer Bastidas 1 Reputation point
    2022-02-18T13:18:24.507+00:00

    Thank you all, I am taking all your recommendations and will review each of the subqueries


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.