separated out the sql conditional composition.