Passing column names from a query result into new query

tumikosha
Participant II

I want to query a table that have over 2k columns and its constantly increase the number of columns. 

We want to get the column names as string (like “Filed1,Field2,...”)  from one query and use this list in another query
How I can do  that?

DECLARE x STRING;
EXECUTE IMMEDIATE
"SELECT " ||
"""STRING_AGG(distinct column_name, ',' order by column_name), """ ||
"FROM `table1`" ||
INTO x;

EXECUTE IMMEDIATE format(
"SELECT " ||
"%s FROM `table2` ", x)
0 0 293
0 REPLIES 0
Top Labels in this Space
Top Solution Authors