Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.

Passing column names from a query result into new query

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 563
0 REPLIES 0
Top Labels in this Space