title: Adding Year and Month to a group by sql query
body: <p>I have the following query where @BeginTime is the first day of the month and @EndTime is the last day of the month .</p>
  
  <pre><code>SET @BeginTime = RTRIM(@BeginTime) + ' 00:00:00'
  SET @EndTime   = RTRIM(@EndTime) + ' 23:59:59'
  
  select C.Name , COUNT(DISTINCT D.Id)  from DriverLic D 
  INNER JOIN Clov C WITH (NOLOCK) ON D.CId = C.CId 
  
  AND ((D.RDate &lt; @EndTime) 
  AND ( D.UrDate &gt; @BeginTime))
  
  group by C.Name
  </code></pre>
  
  <p>I get an output something like this :</p>
  
  <pre><code>Name  Count(D.Id)
  AC        22
  AB        32
  CD        11
  </code></pre>
  
  <p>I would like to get an output something like this : </p>
  
  <pre><code>Year Month Name Count(D.id)
  2013  8     AC      22
  2013  8     AB      32
  2013  8     CD      11
  </code></pre>
  
  <p>Is there a way i can achieve this ?</p>