generate sql string from options