Generate SQL based on ListArray