This is not a complete answer, but it can do something. You can build your query dynamically:
declare @q varchar(1000) set @q = 'select ' + @columnName + ' from table' EXEC(@q)
Otherwise, you can get the selected set of column names from the table (MS T-SQL):
select name from DB.sys.syscolumns where id=( select id from DB.sys.sysobjects where xtype='U' and name='pages' ) where name LIKE '%pages_title'
Not sure how to use this set to query a table for a specific set of columns. Perhaps you could somehow combine these two approaches?
source share