SQLTeam.com | Weblogs | Forums

Return columns on select when column names are listed in another table


I have a legacy system and am trying to find away around one of the designs in it.

Basically there is alot of dynamic sql and all it does is build a select string of column names that are listed in the user pref table.

Has anyone dealt with this scenario? Any suggestions how to refactor to avoid dynamic sql?


If the object names are in a table, then you have to use dynamic SQL if it's within a stored procedure. I suppose you could send the object names back to an application, and then the application could build the queries and execute them as prepared statements which are basically the same as stored procedure when it comes to performance.