I have a query that produces results like the following:
Company     Member          Account     Date        Check-ins
================================================================
Acme, Inc.  Amanda Smith    4145886     7/3/2014    1
Acme, Inc.  Amanda Smith    4145886     7/9/2014    1
Acme, Inc.  Amanda Smith    4145886     7/23/2014   1
Acme, Inc.  Gladys Jones    800138618   7/5/2014    1
Acme, Inc.  Joe Ortega      800123972   7/15/2014   1
Acme, Inc.  Joe Ortega      800123972   7/29/2014   1
Here is the query:
Select 
    com.CompanyName as [Company], 
    p.FirstName + ' ' + p.LastName as [Member],
    a.AccountID as [Account], 
    CAST(mc.CheckInDate AS Date) [Date], 
    count(*) AS [Check-ins]
from 
    gym.Person p 
join 
    gym.AccountPeople ap on p.PersonID = ap.PersonID
join 
    gym.Account a on a.AccountID = ap.AccountID
join 
    gym.MembershipStatus ms on a.MembershipStatusID = ms.MembershipStatusID 
join 
    gym.Company com on a.CompanyID = com.CompanyID
join 
    gym.MemberCheckin mc on mc.PersonID = p.PersonID
where 
    mc.CheckInDate > '2014-7-1'
    and mc.CheckInDate < DATEADD(dd, 1, CAST('2014-7-31' AS Date))
GROUP BY 
    com.CompanyName, a.AccountID, 
    p.FirstName + ' ' + p.LastName, CAST(mc.CheckInDate AS Date)
order by 
    com.CompanyName, p.FirstName + ' ' + p.LastName
I'm puzzling over how to get this a little differently. Notice how Amanda checked in 3 times in July, on the 3rd, the 9th, and the 23rd. I need the results to show the check-in count across every day of the month. So in place of the "Date" column I need 31 columns (for each possible day of the longest possible month), like so:
1   2   3   4   5   6   7   8   9   10 .....
==============================================
0   0   1   0   0   0   0   0   1   0 ......
Notice the "check-in" count under 3 and 9, for July 3rd and July 9th. How can I build the query to produce results like that?
 
     
    