
Assume that you have incoming parameter "ModerationStatus" that is responsible for filtering results.
Depending on this parameter you need to show either all rows or limited number of rows. Here's the example of the routine how this can be made with the least effort:
CREATE PROCEDURE `Photo_Get_List`(ModerationStatus tinyint(1))
BEGIN
SET @query = 'SELECT * FROM Photos';
IF ModerationStatus IS NOT NULL THEN
SET @query = CONCAT(@query, ' WHERE ModerationStatus = ', ModerationStatus);
END IF;
PREPARE statement FROM @query;
EXECUTE statement;
DEALLOCATE PREPARE statement;
END;
Comments
Post new comment