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

  • Home
  • SEARCH
  • 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 5984741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:25:23+00:00 2026-05-22T22:25:23+00:00

SELECT * FROM [productDetail] WHERE Price BETWEEN 0 AND 2000 OR Price BETWEEN 2000

  • 0
SELECT * 
FROM [productDetail] 
WHERE 
     Price BETWEEN 0 AND 2000 
     OR Price BETWEEN 2000 AND 12000 
     AND CategoryID = 2  
     AND caravanOffline = 0 
ORDER BY 
     price

The query doesn’t produce the desired output, it also shows the products whose categoryID is 3,1 etc.

Can any one spot the problem in the query.

Updated code:

static public DataTable GetSelectedFilterMotorhomes(ArrayList caravans)
{

    string sqldefault = "Select * from productDetail Where";
    string sqlBuilder = "";
    int starter = 0;
    int count = caravans.Count;
    string sqlOperator = "OR";

    if (caravans.Count > 0)
    {

        while (count > starter) //build the query depending on the number of caravans.selected.count 
        {

            sqlBuilder += "((Price between " + caravans[count - 1] + "))" + sqlOperator;
            count--;


        }

        string addQuery = sqldefault + sqlBuilder;
        string removeOR = addQuery.Substring(0, addQuery.Length - 2);  //remove OR
        string finalQuery = removeOR + "AND (CategoryID = 2)  AND (caravanOffline = 0)  order by Price"; //Display caravans in ascending order

        SqlDataAdapter da = new SqlDataAdapter(finalQuery, ConnectionString);
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
    }
    else
    {
        string returnAllCaravans = "Select * from productDetail WHERE CategoryID = 2 AND caravanOffline = 0";

        SqlDataAdapter da = new SqlDataAdapter(returnAllCaravans, ConnectionString);
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

}
  • 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-05-22T22:25:24+00:00Added an answer on May 22, 2026 at 10:25 pm

    What do you really want to do with your WHERE clause?? Without any parenthesis, it’s not clear at all what you’re trying to select

    DO you really mean:

    WHERE 
         (Price BETWEEN 0 AND 2000 OR Price BETWEEN 2000 AND 12000)
         AND CategoryID = 2  
         AND caravanOffline = 0 
    

    Price is between 0 and 2000, or between 2000 and 12000 (doesn’t really make sense), AND in any case, the CategoryID is 2 ?

    Or do you mean:

    WHERE 
         Price BETWEEN 0 AND 2000 
         OR 
         (Price BETWEEN 2000 AND 12000 AND CategoryID = 2 AND caravanOffline = 0)
    

    The price is either between 0 and 2000 (with no other restriction) OR the price is between 2000 and 12000, but only if the CategoryID = 2 and CaravanOffline = 0 are true at the same time) ??

    Or are you looking for something else than these two options??

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

Sidebar

Related Questions

SELECT * FROM (SELECT ROW_NUMBER() over ( ORDER BY CASE WHEN @SortExpression ='Country_id' THEN
I have a query which have multiple conditions on on clause SELECT * FROM
SELECT * FROM [makes$] WHERE Corporate Name='Champion Enterprises, Inc.' I'm running this query on
select * from table where key='çmyk' when i run this query on table that
SELECT * FROM Feedback WHERE text =! None Nul , doesn't work either. It
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row, hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
Select * from tableName order by id desc limit 10 How to perform something
select * from tableName where somecode = '$$$$$$$&8Y~$$$$' when I ran this query in
select * from tabName limit 25 by above query I get 25 rows and
SELECT * FROM table1 JOIN table2 ON table1.center BETWEEN table2.left AND table2.right I'm new

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.