How to pass the input parameters to dynamic Pivot stored procedure This is my query:

DELIMITER $$

DROP PROCEDURE IF EXISTS `leavemanagement`.`SP_ViewAttendance` $$
CREATE PROCEDURE `leavemanagement`.`SP_ViewAttendance` (


    IN in_branch_id varchar(10)

)
BEGIN
       SET SESSION group_concat_max_len = 1000000000;

      SET @sql = NULL ;
  SELECT
    GROUP_CONCAT(
      DISTINCT CONCAT(
        'max(CASE WHEN attendance.date = ''',
        DATE_FORMAT(DATE, '%Y-%m-%d'),
        ''' THEN coalesce(p.present, '''') END) AS `',
        DATE_FORMAT(DATE, '%Y-%m-%d'),
        '`'
      )
    ) INTO @sql
  FROM
    calendar ,attendance
  WHERE DATE &gt;= '2015-02-02'
    AND DATE &lt;= '2015-02-31' ;



  SET @sql = CONCAT(
    ' SELECT  ',in_branch_id, @sql,'
        from
            (
               select c.date,  a.user_id ,a.user_name,a.attendance_id,a.attendance_date
                 from calendar c
                 cross join attendance a
            ) attendance
            left join attendance  p
              on attendance.user_id= p.user_id
              and attendance.date = p.attendance_date

           where attendance.date&gt;= date
              and attendance.date &lt;= date
              and attendance.branch_id = in_branch_id (---------HERE IM PASSING IN PARAM)

          group by attendance.user_id'
  ) ;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END $$

DELIMITER ;


But it is showing error:


  FUNCTION leavemanagement.1max does not exist


I don't know how to pass parameters in Pivot Query.
I'm passing input parameter in_branchId into pivot Mysql Query 

DROP PROCEDURE IF EXISTS `leavemanagement`.`SP_ViewAttendance` $$
    CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_ViewAttendance`(

              IN in_attendance_start_date DATETIME,
        IN in_attendance_end_date DATETIME,
        In in_branchId varchar(100)
    )
    BEGIN
          SET SESSION group_concat_max_len = 1000000000;

          SET @sql = NULL ;
      SELECT
        GROUP_CONCAT(
          DISTINCT CONCAT(
            'max(CASE WHEN attendance.date = ''',
            DATE_FORMAT(DATE, '%Y-%m-%d'),
            ''' THEN coalesce(p.present, '''') END) AS `',
            DATE_FORMAT(DATE, '%Y-%m-%d'),
            '`'
          )
        ) INTO @sql
      FROM
        calendar ,attendance
      WHERE DATE &gt;= in_attendance_start_date
        AND DATE &lt;= in_attendance_end_date
          AND attendance.branch_id = in_branchId;




      SET @sql = CONCAT(
        ' SELECT  ', @sql,'
            from
                (
                   select c.date,  a.user_id ,a.user_name,a.attendance_id,a.attendance_date
                     from calendar c
                     cross join attendance a
                ) attendance
                left join attendance  p
                  on attendance.user_id= p.user_id
                  and attendance.date = p.attendance_date

               where

                      attendance.date&gt;= date
                  and attendance.date &lt;= date
                  AND p.branch_id = ',in_branchId,' GROUP BY attendance.user_id') ;


    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;