extract common sql segment