alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

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

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; 

54 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online