Erik Darling embraces dynamic SQL:
You’ve got tables. So many tables And columns. So many columns.
Users — demanding as they are — might wanna see, search, and order by all sorts of things in those many columns in those many tables. Writing a query to do that is hard at first, especially if you’re afraid of dynamic SQL.
Read on for reasons why dynamic SQL is usually the right answer here and check out a video as well.