Generate select statement