Extract SQL case to switch statement.