@wg992 I achieved the transformation of your sample data using a macro I recorded which carried out conventional editing, searching and copy/paste operations. The macro acted on a single pair of corresponding D1. rows. I then ran the macro as many times as needed.
Note that within a macro, all of these operations are fully supported: selecting text, launching a search on that text via Ctl-F3, search again with F3, and, fresh clipboard copy/paste operations.
Care is needed in regard to the cursor position before launching the macro, and, where the macro leaves the cursor.
There are caveats, and your actual files may contain features that prevent this approach from being a desirable “all in one go” solution.
For instance if a file contains a large number of separate outer level SELECT {} structures, using the simple macro I used (which worked on the first try) will be cumbersome in that you’ll have to manually position the cursor between batches of macro runs. However, a more devious macro which incorporates a regex search (for the 1st instance of D1\d\. AS following SELECT) could be devised to overcome that.