lundi 6 mars 2017

if conditions are not working after where clause in Mysql Store Procedure

Hi i am creating a Mysql Store Procedure.What i want to do here is to add multiple and conditions if parameters values are not empty.I have written a query inside a store procedure but it is not working.

Here is the query

BEGIN

    Select c.user_id,u.fname,u.lname,u.email,c.name,c.raised_amount,c.goal_amount,c.created_at from users u
    INNER JOIN city c on u.id = c.user_id 

    WHERE c.user_id=user_id 

    IF( city_name !='', and c.name LIKE CONCAT('%',city_name, '%') , 1)

    IF( city_raised_max != '' AND city_raised_min != '', and c.raised_amount BETWEEN city_raised_min AND city_raised_max , '%'), 1);   

END

These three are the parameters

1)user_id

2)city_raised_min

3)city_raised_max

what i want to here is that i want to add multiple and conditions if parameters are not empty.

but the query is giving me syntax error on this line you have an error in your sql syntax error check the manual that corresponds to your mysql server version for the right syntax near.

IF( city_name !='', and c.name LIKE CONCAT('%',city_name, '%') , 1)

Kindly help me on this issue i have trying to resolve this for 1 day but still no success.

Thanks and Regards

Aucun commentaire:

Enregistrer un commentaire