goal
Use the where clause only if the parameter is non-zero.
Problem
I do not know the syntax.
What i have
The following syntax does not work.
CREATE DEFINER=`root`@`localhost` PROCEDURE `getProductsListForHome` (IN `inOffer` INT, IN `categoryId` INT) BEGIN SELECT (MIN(`map`.`Product_Price`)) as `minProductPrice`, (MAX(`map`.`Product_Price`)) as `maxProductPrice`, `pr`.`Product_Name` as `productName`, `ca`.`Category_Name` as `categoryName` FROM `bm_market_products` as `map` JOIN `bm_products` as `pr` ON `map`.`Product_Id` = `pr`.`Product_Id` JOIN `bm_products_category_relationship` as `car` ON `pr`.`Product_Id` = `car`.`Product_Id` JOIN `bm_product_categories` as `ca` ON `car`.`Category_Id` = `ca`.`Category_Id` WHERE `map`.`Product_State` = inOffer IF (`categoryId` != null) THEN AND `ca`.`Category_Id` = `categoryId` END IF; GROUP BY `map`.`Product_Id`; END
The problem is line 19.
Duplicate question?
I do not think so. I am looking for about this subject, but without success - then I came here to publish.
More details
I read about control flow functions here , but it still confuses me.
Thanks in advance!
source share