fix bug when use 'for' loop in dynamic sql