Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:36:37+00:00 2026-06-06T17:36:37+00:00

Hi I am trying to execute a query to get row between certain number

  • 0

Hi I am trying to execute a query to get row between certain number , Like i am trying to get rows between 10-20. so i am using subquery so that i can use row_number() function

The query fails with the error:

SQL subquery return more that 1 value

So I need to figure a way out because I need to get more that 1 resulset out of the query

PROCEDURE dbo.Search

    (
    @search_text varchar(max), 
    @search_category varchar(max),
    @page int,
    @COUNT INT OUTPUT
    )

AS

     SET NOCOUNT ON
     DECLARE @Lower_limit int = (@page-1)*10;
     DECLARE @Upper_limit int = (@page * 10) + 1;
    -- SET @COUNT =0
     IF @search_category='deal'
     BEGIN
        SET @COUNT = (SELECT COUNT(*) FROM dealData WHERE dealInfo LIKE  '%' + @search_text + '%' OR dealName LIKE '%' + @search_text + '%' OR dealDescription LIKE  '%' + @search_text + '%' GROUP BY dealId);
        SELECT x.dealId , x.ROW 
        FROM
        ( SELECT dealId,ROW_NUMBER() OVER(ORDER BY dealId) as ROW from dealData WHERE dealInfo LIKE  '%' + @search_text + '%' OR dealName LIKE '%' + @search_text + '%' OR dealDescription LIKE  '%' + @search_text + '%'  GROUP BY dealId)x   
        WHERE x.ROW < @Upper_limit AND x.ROW > @Lower_limit
     END

This is the full procedure and when i try to call it from the following code I get exception at _command.ExecuteReader(); Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

 _query = "Search";
                _command = new SqlCommand(_query, _connection);
                _command.CommandType = CommandType.StoredProcedure;
                _command.Parameters.AddWithValue("@search_text", search_text);
                _command.Parameters.AddWithValue("@search_category", search_category);
                _command.Parameters.AddWithValue("@page", page);
                var returnParameter = _command.Parameters.Add("@COUNT", SqlDbType.Int);
                returnParameter.Direction = ParameterDirection.Output;
                _reader = _command.ExecuteReader();
                while (_reader.Read())
                {
                    search_result index = new search_result();
                    index.category_id = this._categoryIdFromName(search_category);
                    index.post_id = _reader.GetValue(0).ToString();
                    _searchList.Add(index);
                }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:36:39+00:00Added an answer on June 6, 2026 at 5:36 pm

    The problem is this part of your sp:

    SET @COUNT = (  SELECT COUNT(*) FROM dealData 
                    WHERE dealInfo LIKE  '%' + @search_text + '%' 
                    OR dealName LIKE '%' + @search_text + '%' 
                    OR dealDescription LIKE  '%' + @search_text + '%' 
                    GROUP BY dealId)
    

    Specifically, the GROUP BY dealId part. If you have multiple dealId on that table, then you are going to get multiple rows as a result. Obviously, you can’t assign that on a scalar variable. Either @Count will need to be declared as a table variable (which will change the logic of the rest of your sp), or you get rid of the GROUP BY dealId, and verify that it gives you your desired results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute a query but I get an error: Unknown table alias
I'm trying to execute a query with the Tornado's database wrapper , like this
I'm trying to execute a query that currently works in phpMyAdmin but it does
I'm trying to get this working and the query executes but nothing comes back.
I am trying to execute following query: Insert into pligg_links_temp select * from pligg_links
I was trying to execute a query which gets me all the info from
I am trying to execute the following query in oracle but not able to
I am trying to execute the following query. update share set holder = 22
I am trying to execute the following Query select distinct pincode as Pincode,CAST(Date_val as
I've been trying to execute this mysql query in my php file however I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.