title: SQL Server - Get first date in a week, given the week number?
body: <p>I've got a query (for use in bug tracker.net) that calculates the number of bugs by week by status.  But the query returns the week number, what I really want is the first date of the week</p>
  
  <pre><code>select datepart(wk, DateAdd(day, 0, DateDiff(day, 0, bg_reported_date)))
         as [week], bg_status , st_name as [status], count(*) as [count] 
    from bugs inner join statuses on bg_status = st_id 
   group by datepart(wk, DateAdd(day, 0, DateDiff(day, 0, bg_reported_date))),
            bg_status, st_name
   order by [week], bg_status
  </code></pre>
  
  <p>The part that gets the week number is </p>
  
  <pre><code>datepart(wk, DateAdd(day, 0, DateDiff(day, 0, bg_reported_date))) as [week]
  </code></pre>
  
  <p>It returns this output:</p>
  
  <pre><code>week        bg_status   status                                        count
  ----------- ----------- --------------------------------------------- ------
  22          1           new                                           1
  22          5           closed                                        32
  </code></pre>
  
  <p>But it would be better to say the first date of each week, eg 01-01-2010, then 08-01-2010, etc</p>
  
  <p>Question is not a duplicate of <a href="https://stackoverflow.com/questions/1267126/how-do-you-get-the-week-start-date-and-week-end-date-from-week-number-in-sql">How do you get the &quot;week start date&quot; and &quot;week end date&quot; from week number in SQL Server?</a> (answer says how to get week start from a date not from a week number)</p>
  
  <p>Not a duplicate of <a href="https://stackoverflow.com/questions/662379/calculate-date-from-week-number">Calculate date from week number</a> (question asks for c#)</p>
  
  <p>Not a duplicate of <a href="https://stackoverflow.com/questions/1036613/get-first-date-of-week-from-provided-date">Get first date of week from provided date</a> (question asks for javascript)</p>
  
  <p>I did search but couldn't find this question answered for SQL Server (2010 if it matters)</p>