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.
You have to declare the variables, then you can use them to assign the values in the
SELECTand use them later:Or you can make a single query if these 3 variables are not used elsewhere: