Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

MySQL: SImple update query for stored procedure with nested If giving syntax error in SQL ?

By M.K. Verma · 4 May 2022

MySQL: SImple update query for stored procedure with nested If giving syntax error in SQL ?

It looks like you're trying to set the value, and then a category based on the value. It would be a lot cleaner with a CASE statement like:

UPDATE chicago_public_schools
SET
    Leaders_Score = inLeaderScore,
    Leaders_Icon = CASE WHEN inLeaderScore > 80 THEN 'Very Strong'
                        WHEN inLeaderScore > 60 THEN 'Strong'
                        WHEN inLeaderScore > 40 THEN 'Average'
                        WHEN inLeaderScore > 20 THEN 'Weak'
                        WHEN inLeaderScore > 0 THEN 'Very Weak'
                    END
WHERE
    School_ID = inSchoolID;