generate sql with view