title: How to merge two similar queries working based on if-else into one
body: <p>I have a query like below (SQL Server 2008):</p>
  
  <pre><code>if (@checkValue = 1) 
  begin
  
    select *
    from table1 t
    inner join table2 t2 on t.Id = t2.t_Id
                        and DATEDIFF(hour,t2.Start,t.Start) &lt; 24
  
  end
  else 
  begin
  
    select *
    from table1 t
    inner join table2 t2 on t.Id = t2.t_Id
                         and Convert(Date, t.Start) = Convert(Date,t2.Start) 
  
  end
  </code></pre>
  
  <p>I am not happy with this query since I basically duplicated the main query and made a slight change. I am looking for a more professional way, like merging the queries into 1 by adding a where clause maybe. I appreciate if someone helps. Thanks.</p>