Corrected SQL execution if-else statement