title: How to add to Where clause depending on parameter value
body: <p>I have an sql query that I am wanting to run and want to add something to the where clause if I mark a parameter as true. I didn't think I would need to have the same sql statement twice, but can't find a way to do this. This is what I want. </p>
  
  <pre><code>DECLARE @getShipped VARCHAR = 'false'; 
  
  SELECT DISTINCT 
      Serial_No
  INTO #Serials
  FROM Part_v_Container_Change2 AS CC
  WHERE Change_Date &lt;= @dateEnding
     *** AND IF @getShipped = 'true' THEN CC.Container_Status = 'Shipped' ***
  </code></pre>
  
  <p>Have tried if statements and case statements but can't seem to get this to work? I just don't want to repeat sql if I don't have too. </p>