0

I tried this much but after 10th column it throws an error of mysql syntax

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from emp_details a join emp_attendance b on b.emp_id=a.emp_id and b.time_in l' at line 1

DELIMITER $$
    DROP PROCEDURE IF EXISTS `attendance_reg`.`new2` $$
CREATE PROCEDURE new2 (IN ddl1 varchar(100))
BEGIN
SET @sql = NULL;
SET @vardomain := CONCAT(ddl1,'%');
    select GROUP_CONCAT(DISTINCT
               CONCAT(' Max(CASE WHEN DATE_FORMAT(b.time_in, ''%D %M'') = ''',
                       DATE_FORMAT(time_in, '%D %M'),
                       ''' THEN b.status END) AS ''',
                       DATE_FORMAT(time_in, '%D %M'), ''''
                     )
                  ORDER BY time_in)
                  INTO @sql
    from emp_attendance   where time_in like @vardomain;
    SET @sql = CONCAT('SELECT b.emp_id ,a.emp_name ,', @sql, ' from emp_details a  join emp_attendance b  on b.emp_id=a.emp_id  and b.time_in like ',@vardomain,' Group By a.emp_name order by a.emp_dept,a.emp_name');
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    END $$

DELIMITER ;
  • I don't really know what the relation between "10 rows" and your error message (which would imply no result) means, but with `group_concat`, the most likely suspect making trouble is the maximum length of the resulting string, try e.g. [MySQL and GROUP_CONCAT() maximum length](http://stackoverflow.com/questions/2567000/mysql-and-group-concat-maximum-length) – Solarflare Jan 17 '17 at 09:42
  • Thanks...It worked...but i can't mark it as answer as you commented in comment section....but still thanks... :) – nand rani mehta Jan 17 '17 at 09:55

0 Answers0