gautam_reddyc
asked on
IF condition inside a stored procedure
I get an error pointing to the if loop when I am creating this stored procedure. Is there any other method to use the conditional and what is the syntactical error that I am making??
delimiter //
CREATE DEFINER=`root`@`localhost` PROCEDURE `getData1`(IN templateName VARCHAR(45),IN templateVersion VARCHAR(45),IN userId VARCHAR(45))
BEGIN
set @version = CONCAT("SELECT 'saveOEMsData_answersVersion' FROM `saveOEMsData` where saveOEMsData_templateName = '",templateName,"' and saveOEMsData_templateVersion = ",templateVersion," and saveOEMsData_userId= ",userId," GROUP BY `saveOEMsData_templateName`");
PREPARE s1 from @version;
EXECUTE S1;
IF(@version==1) THEN select 'one';
ELSE select 'zero';
END IF;
END
//
delimiter ;
ASKER
hey rosenet!! I am able to compile the procedure, but there seems to be a confusion. The variable @version holds the whole query statement and not just the value of version.
How do only retrieve the version so that I can compare using the IF conditional?
How do only retrieve the version so that I can compare using the IF conditional?
Oh completely my fault I didn't realize you were working with MySQL I gave you an answer for SQL Server.
Sorry for the confusion I don't think I can help you.
Sorry for the confusion I don't think I can help you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks soLost & rosenet!
IF(@version==1) THEN select 'one';
should be
IF(@version=1) THEN select 'one';