CREATE PROCEDURE `spGetContentList` ( IN `P_TeacherId` INTEGER , IN `P_AssignContent` INTEGER , IN `P_FolderName` VARCHARACTER (?) , IN `P_IsOrderBy` INTEGER , IN `P_ContentTypeId` INTEGER ) BEGIN IF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontent` WHERE `TeacherId` = `P_TeacherId` ) THEN SELECT `Id` , `ContentTypeId` AS `ContentTypeId` , `Concat` ( `ContentPath` , ? , `id` ) AS `Path` , `ContentTitle` AS `Title` , `ContentLink` AS `Link` , `CreatedDatetime` AS `CreatedDateTime` , `IsCommon` AS `IsCommon` , `Duration` AS `Duration` FROM `tteachercontent` WHERE `TeacherId` = `P_TeacherId` AND `ContentPath` = `P_FolderName` AND `IsCommon` = ? AND ( `ContentTypeId` = `P_ContentTypeId` OR `P_ContentTypeId` = ? ) ORDER BY CASE WHEN `P_IsOrderBy` = ? THEN `tteachercontent` . `ContentTypeId` WHEN `P_IsOrderBy` = ? THEN `tteachercontent` . `CreatedDateTime` END DESC , CASE WHEN `P_IsOrderBy` = ? THEN `tteachercontent` . `ContentTitle` END ASC ; END IF ; ELSEIF `P_AssignContent` = ? THEN IF EXISTS ( SELECT ? FROM `tteachercontentassign` INNER JOIN `tteachercontent` ON `tteachercontent` . `id` = `tteachercontentassign` . 