Make slicing for SQL statements more robust