Tuesday, April 5, 2011

MySQL Stored Procedure - IF/ELSE on the data returned

Essentially what I need to do is pull someone's age from the database which is stored as an integer and then perform a check as to whether they are over 18 or not.

The simple select of the row returns their age. The goal is to have the Row return either a "yes" or "no" if they are over the age of 18.

Normally I'd do this logic when the data was returned but the requirements are outside of my control.

From stackoverflow
  • select if(age>=18,'yes','no') as over_18 
    from age_table
    

0 comments:

Post a Comment