title: Display Monthly Attendance Report With Dynamic Dates in MySql Stored Procedure
body: <pre><code>STUDENTNAME   | ROLLNO | CLASS | 2013-06-01 | 2013-06-02 | 2013-06-03 | 2013-06-04 | 2013-06-05 | 2013-06-06 | 2013-06-07 | 2013-06-08 | 2013-06-09 | 2013-06-10 |
  ------------------------------------------------------------------------------------------------------------------------------------------------------------------
  |       Naren |      1 |    22 |          A |          A |          A |          A |          P |          P |          P |          P |          P |          P |
  |       Srinu |      2 |    22 |          P |          P |          P |          P |          P |          P |          P |          P |          P |          P |
  |        Blah |      3 |    22 |          A |          P |          P |          P |          P |          P |          P |          P |          P |          P |
  </code></pre>
  
  <p>I want the Attendance Report Like That </p>
  
  <p>My Attendance Table is </p>
  
  <pre><code>Att_id   User_id    Attendance_date Present/Absent
  1          1              2015-01-01    P
  2          2              2015-01-01    L
  3          1              2015-01-02    P
  4          2              2015-01-02    P
  5          1              2015-01-03    L
  6          2              2015-01-03    L
  </code></pre>
  
  <p>i have one Stored Procedure</p>
  
  <pre><code>SET @sql = NULL;
  SELECT
    GROUP_CONCAT(DISTINCT
      CONCAT(
        'max(CASE WHEN ca.date = ''',
        date_format(date, '%Y-%m-%d'),
        ''' THEN coalesce(p.present, '''') END) AS `',
        date_format(date, '%Y-%m-%d'), '`'
      )
    ) INTO @sql
  FROM calendar
  where date&gt;='2013-06-01'
    and date &lt;= '2013-06-05';
  
  SET @sql 
    = CONCAT('SELECT ca.user_id,
                 ', @sql, ' 
              from
              (
                select c.date, a.user_id
                from calendar c
                cross join attendance a
              ) ca
              left join attendance  p
                on ca.user_id= p.user_id
                and ca.date = p.attendance_date
              where ca.date&gt;=''2013-06-01''
                and ca.date &lt;= ''2013-06-05''
            group by ca.user_id');
  </code></pre>
  
  <p>but here What is <code>@sql</code>. I didn't understood This Sql Store Procedure</p>
  
  <p>Plz can you write in Mysql Stored Procedure </p>