Generate SELECT For All Columns
September 13, 2016 Hey, Mike
|
I have a table with a long list of column names and I want to build a SELECT statement from the catalog metadata. If I supply schema (library) and table (physical file) names, is there a way to generate a SELECT statement? —Four Hundred Guru Reader Thanks to dynamic compound statements and global variables, the answer is yes, it’s fairly easy to construct a SQL statement for a table or view as shown below:
/* Build Select Statement and stuff it in QGPL.TEMPSQL variable */
BEGIN
-- Fill in your table/schema name
DECLARE @TABLE_NAME VARCHAR(128) NOT NULL
DEFAULT 'SYSCOLUMNS'; |


