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 7409077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:01:17+00:00 2026-05-29T06:01:17+00:00

I have a problem where the user has set his preferences in a table.

  • 0

I have a problem where the user has set his preferences in a table.

The table has more than 5 columns. Now I want to search the other view with condition values that are in the preference table.

Example:

The Preference table has price range, colour etc

So I need to search the products with price and colours.

Now I want to do it in SQL Server itself i.e. passing the preference id, it will always return a single row and then from the columns get the values like min price, max price and then create a search query.

The Issue is I dont know that how I can store the preference row column values in variables so that I can use it.

I am using Entity Framework so that I cannot using Dynamic SQL too.

I only want to know the way by which I can store the column values of preference table.

  • I only know that i can do it something like:

    @colour = Select Top 1 Colour from preferences;
    

But like this I need to write this query for every variable. Is there is some better way with something called as CTE etc.

  • 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-29T06:01:19+00:00Added an answer on May 29, 2026 at 6:01 am

    You have to declare the variables, then you can use them to assign the values in the SELECT and use them later:

    -- declare the variables
    DECLARE @min_price decimal(8,2)
    DECLARE @max_price decimal(8,2)
    DECLARE @color varchar(20)
    
    -- assign the values into the variables
    SELECT 
        @min_price = MIN_PRICE
      , @max_price = MAX_PRICE
      , @color = Colour
    FROM Preference
    WHERE preference_id = (parameter of prefrence id)
    
    -- Now you get all 3 values of Colour, Min Price, Max Price,
    -- then these 3 values can be used for your query
    
    SELECT *
    FROM products 
    WHERE colour = @color 
        AND price BETWEEN min_price AND @max_price
    

    Or you can make a single query if these 3 variables are not used elsewhere:

    SELECT *
    FROM products p
    INNER JOIN
    (
      SELECT Colour, MIN_PRICE, MAX_PRICE
      FROM Preference
      WHERE preference_id = (parameter of prefrence id)
    ) pre ON (p.colour = pre.Colour AND p.price BETWEEN pre.MIN_PRICE AND pre.MAX_PRICE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of a problem with user controls. Basically what I want
The problem: I have set of pictures, when the user presses on one of
On my website's Start page I have a Search Mask where user set select
I have a problem with the MySQL root user in My MySQL setup, and
I have a problem regarding getting the path of a user control. The scenario
I have a problem for querying records into mysql explanation below The user could
I have a problem that i cant solve :( I have a user control
i still have a problem to develop a convenient app to the user. because
I have the following problem: I have an Activity where a user can start
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User

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.