title: SQL Query to itemized Daily Sales Per Month
body: <p>In my Sales Table, listed is the daily sales of particular tenant in one Property.</p>
  
  <p><strong>Using this code</strong>, I was able to list or select daily Sales of tenants, summed up based on grouping of Property.</p>
  
  <pre><code>SELECT  date , location ,  SUM(a.gsc) Sales
  FROM  SalesTable
  WHERE (date  BETWEEN  '01/01/2015'   AND '12/31/2015' ) 
        and (location  = 'Property1')
  GROUP BY location ,  date
  ORDER BY location, date
  </code></pre>
  
  <p><strong>And the result is something like this</strong></p>
  
  <pre><code>Date         Location     Sales
  01/01/2015   Property1    10,000
  01/02/2015   Property1    20,000
  .
  .
  .
  12/31/2015   Property1    15,000
  </code></pre>
  
  <p>What I wish to accomplish as the final output is make the result in tabular form having Days date as the first Row and Month as the columns. <strong><em>Please see sample output for further illustration.</em></strong></p>
  
  <pre><code>Date  January              February               
        Date   Day  Sales    Date    Day  Sales
  1     1-Jan  Fri  10,000   1-Feb   Mon  9,000
  2     2-Jan  Sat  20,000   2-Feb   Tue  10,000
  3     .      .    .        .       .    .
  4     .      .    .        .       .    .
  5     .      .    .        .       .    .
  6    
  7
  8
  .
  .
  .
  .
  .
  31
  </code></pre>
  
  <p><strong>This is what I tried</strong></p>
  
  <pre><code> SELECT  date , location ,  SUM(a.gsc) Sales
   INTO #TempTable1
   FROM  SalesTable
   WHERE (date  BETWEEN  '01/01/2015'   AND '12/31/2015' ) 
            and (location  = 'Property1')
   GROUP BY location ,  date
   ORDER BY location, date
  
  
  
      SELECT   months.number, tenants.locationd   ,  tenants.location       
          ,(case when (t.DATE) = 1  then t.gsc end) as 'January'
          ,(case when (t.DATE) = 2 then t.gsc end)) as 'February'
          (case when year(t.DATE) = 3 then t.gsc end) as 'March'
  
           FROM 
              (       
                      SELECT Number 
                      FROM master..spt_values 
                      WHERE Type = 'P' and Number between 1 and 31
              ) months
              CROSS JOIN
              (       --12 Month Name will be cross joined sa selected tenant/s
                      SELECT DISTINCT  locationd ,  location
                      FROM #AMRDSR1
              ) tenants    
  
      LEFT JOIN #AMRDSR1 t   
       ON months.number = datepart(day,t.date) and tenants.location = t.location 
      GROUP BY  months.number, tenants.locationd  , tenants.location , t.date, t.gsc 
      ORDER BY  tenants.locationd ,  datepart(day,t.date)
  </code></pre>
  
  <p>I have been suggested to used pivot, but that is quite new to me and seemed to be very complicated, If there are ways to do it just using TSQL, much better. </p>
  
  <p>Hoping for your expert advice.</p>
  
  <p>Thank you!</p>