Removal of MYSQL if statements and replaced with SQL CASE statements that should be more universal. Andres please test and report back. #244