mercredi 9 novembre 2016

If..then statement in mysql

I have stored procedure with one parameter called paramType (INT)

I'm wondering is there any way how to implement next situation in mysql:

BEGIN
SELECT Code, Price, Type  FROM table
IF paramType IS NOT NULL THEN
WHERE Type = paramType
ELSE
SELECT Code, Price Type  FROM table
END;

So, if paramType is null (empty) then just execute SELECT Code, Price, Type FROM table but if paramType contains value than execute query with condition like:

SELECT Code, Price Type  FROM table WHERE Type = paramType

Or is there other solution without if/then/else?

Aucun commentaire:

Enregistrer un commentaire