title: Dynamic AND clause
body: <p>Within a stored proc ,I want to include an AND clause in a query only if a particular condition is satisfied.</p>
  
  <pre><code>INSERT INTO #firstResults   
   SELECT x, y, z  FROM ep  
   WHERE ep.proposedBy = @Id  
   AND ep.pId IN ( SELECT DISTINCT pId FROM #tempProj)
  </code></pre>
  
  <p>The 'AND' clause should join in only when the #tempProj is not empty.<br>
  What is the most elegant way to implement this?</p>
  
  <p>I am on sql server 2008.<br>
  Since this would be repeated several times over the proc,I wish to avoid branching IF statements.</p>