Executing a SQL query multiple times