CREATE PROCEDURE `spGetContentPath` ( IN `P_ContentId` INTEGER , IN `P_AssignContent` INTEGER ) BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK ; SELECT ? ; END ; IF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontent` WHERE `Id` = `P_ContentId` ) THEN SELECT `CONCAT` ( `ContentPath` , ? , `id` , ? , `ContentTitle` ) AS `ContentPath` FROM `tteachercontent` WHERE `id` = `P_ContentId` ; ELSE SELECT ? ; END IF ; ELSEIF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontentassign` WHERE `Id` = `P_ContentId` ) THEN SELECT `CONCAT` ( `tteachercontentassign` . `ContentPath` , ? , `tteachercontentassign` . `id` , ? , `tteachercontentassign` . `ContentTitle` ) AS `ContentPath` FROM `tteachercontent` INNER JOIN `tteachercontentassign` ON `tteachercontentassign` . `TeacherContentId` = `tteachercontent` . `id` WHERE `tteachercontentassign` . `id` = `P_ContentId` ; ELSE SELECT ? ; END IF ; ELSEIF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontentassign` WHERE `TeacherContentId` = `P_ContentId` ) THEN SELECT `CONCAT` ( `ContentPath` , ? , `id` , ? , `ContentTitle` ) AS `ContentPath` FROM `tteachercontentassign` WHERE `TeacherContentId` = 