Move sql statement to table