title: Store a single sql server row in variable and then use the column values to construct a query
body: <p>I have a problem where the user has set his preferences in a table.</p>
  
  <p>The table has more than 5 columns. Now I want to search the other view with condition values that are in the <code>preference</code> table.</p>
  
  <p>Example:</p>
  
  <p>The <code>Preference</code> table has <code>price range</code>, <code>colour</code> etc</p>
  
  <p>So I need to search the products with price and colours.</p>
  
  <p>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 <code>min price</code>, <code>max price</code> and then create a search query.</p>
  
  <p>The Issue is I dont know that how I can store the preference row column values in variables so that I can use it.</p>
  
  <p>I am using Entity Framework so that I cannot using Dynamic SQL too.</p>
  
  <p>I only want to know the way by which I can store the column values of preference table.</p>
  
  <ul>
  <li><p>I only know that i can do it something like:</p>
  
  <pre><code>@colour = Select Top 1 Colour from preferences;
  </code></pre></li>
  </ul>
  
  <p>But like this I need to write this query for every variable. Is there is some better way with something called as CTE etc. </p>