title: sql sp year or year and month
body: <p>I have some SP that takes year and month:</p>
  
  <pre><code>Create PROCEDURE Report(
      @targetYear int,
      @targetMonth int
  )
  </code></pre>
  
  <p>And querying it with:</p>
  
  <pre><code>select sum(col) where year(dateTime) = @targetYear and month(dateTime) = @targetMonth
  </code></pre>
  
  <p>Then I have the same thing for year only</p>
  
  <pre><code>Create PROCEDURE Report(
      @targetYear int
  )
  </code></pre>
  
  <p>and querying it like:</p>
  
  <pre><code>select sum(col) where year(dateTime) = @targetYear
  </code></pre>
  
  <p>Of course, the logic is more complicated than sum(col)</p>
  
  <p>My question is, how can I write this SP so the logic is not repeated across the two SP, even if it means passing 0 for target month when I mean the whole year?</p>