Using SELECT result as a column name in WHERE clause

Solution 1:

Although you can set up a dynamic SQL statement, I often find this type of operation is easier to do in Excel. Write a query to get the column name and table name for the ones you are interested in.

Then, load these into Excel.

In another cell, put in a string like 'delete from @table where @column = 1'.

Then put in the formula:

=substitute(substitute(<where the string is>, '@table', <tablename>), '@column', <columnname>))

Copy the code back to your database interface and execute it.

(And any spreadsheet will do. I usually have Excel handy.)