• I'm not going to judge the merits of the problem. But I am going to point out a small but important thing that I see crop up frequently:

    '[' + COLUMN_NAME + ']'

    isn't a whole lot better than just COLUMN_NAME - what if they have a ']' in a column name ?

    QUOTENAME(COLUMN_NAME,'[')

    is much better