title: SQL Server Dynamic Condition for Where
body: <p>Assuming I have two tables:</p>
  
  <ul>
  <li>Students : Id, Name, Age, Class, etc</li>
  <li>Conditions : Id, Condition</li>
  </ul>
  
  <p>The Column Conditions.Condition contains a SQL Condition for example "std.Age >2" or "std.Class = 3"</p>
  
  <p>I want somthing that does the following:</p>
  
  <pre><code>SELECT std.Id as StudentId, con.Id as ConId
  FROM   Students as std,
         Condition as con
  WHERE  con.Condition
  </code></pre>
  
  <p>Maybe a function that takes Student Id?</p>
  
  <p>How do I achieve this?</p>
  
  <hr>
  
  <p>Students:</p>
  
  <pre><code>1 , Yossi, 25, 3..
  2 , David, 22, 3..
  3 , Jhon, 5, 2..
  4 , Smith, 25, 4..
  </code></pre>
  
  <p>Conditions:</p>
  
  <pre><code>1 , Age &gt; 3
  2 , Class = 4
  3 , Name LIKE '%i%'
  </code></pre>
  
  <p>result would be (Condition, Studnet):</p>
  
  <pre><code>(1,1) (1,2) (1,3) (1,4) // all are older than 3
  (2,4)                   // only Smith is in class 4
  (3,1) (3,2) (3,4)       // all except jhon have an i in their name
  </code></pre>