使用IF ELSE的存储过程

时间:2019-05-09 02:21:45

标签: mysql

CREATE DEFINER=`root`@`localhost` PROCEDURE `Select_lampiran`(IN `p_id` INT, IN `bulan` INT, IN `tahun` INT,
IN `kodeapp` VARCHAR(255), IN `kodeuser` VARCHAR(255))
BEGIN
SET SESSION group_concat_max_len = 1000000;
SET @sql1=(
    SELECT GROUP_CONCAT(
        DISTINCT 'MAX(IF(DAY(tbabsenpeg.tgl)=',id,',
        TIME_TO_SEC(TIMEDIFF(tbabsenpeg.masuk,tbjamguru.masuk)),
        IF(tbjammasukguru.hari=DAYNAME(tbabsenpeg.tgl),
        TIME_TO_SEC(TIMEDIFF(tbabsenpeg.masuk, tbjammasukguru.masuk)),""))) AS masuk',id
        )
    )
    FROM tbtgl
    WHERE id <= p_id
);

如果分支存在问题。如果将执行表tbjamguru (TIME_TO_SEC(TIMEDIFF(tbabsenpeg.masuk,tbjamguru.masuk)))中显示的数据。其他TIME_TO_SEC(TIMEDIFF(tbabsenpeg.masuk, tbjammasukguru.masuk))将被执行。

0 个答案:

没有答案