You could, instead, execute SQL iteratively. Then you are going to have to use cursors. Here is the order of operations then:
- OPEN the cursor
- FETCH data from the cursor
- DELLOCATE the cursor
- CLOSE the cursor
I find that there are some operations that are so complicated, or volume so huge, that a set based approach just does not work. In those scenarios, I put cursors to work. There might be some optimizations to committing the changes in batches to make this work as fast as possible. It is sometimes just a necessary evil to go iterative.