Hi,
this is my stored procedure on database MySql version 8.0.17
CREATE DEFINER=`root`@`%`PROCEDURE`SP`(IN tun CHAR(100), tmonth CHAR(100))BEGINIFRIGHT(tun,2) = '00'THENSET @s = CONCAT('SELECT * FROM `t_ri` WHERE LEFT (t.un, 2) = LEFT(\'',tun,'\',2);');
ELSESET @s = CONCAT('SELECT * FROM `t_ri` WHERE t.un = \'',tun,'\';'); ENDIF;PREPARE stmt FROM @s;EXECUTE stmt;DEALLOCATEPREPARE stmt;SELECT @s;END
I need insert a new IF
condition in stored procedure when the value of variable tmonth
is not null.
If variable tmonth
is not null and RIGHT(tun,2) = '00'
the query it should be
SET @s = CONCAT('SELECT * FROM `t_ri` WHERE LEFT (t.un, 2) = LEFT(\'',tun,'\',2) AND tmonth = \'',tmonth,'\';');
else
SET @s = CONCAT('SELECT * FROM `t_ri` WHERE t.un = \'',tun,'\' AND tmonth = \'',tmonth,'\';');
I have tried multiple conditions but none have ever worked… can you help me?