sperate sql code from logic