generate sql from options