Netezza: select all columns with name like %X from Y% tables
Posted: Thu Feb 01, 2018 3:30 pm
First off, forgive me if this is not the right place for this, I'm not sure where else to ask, and please feel free to flag and close if this is inappropriate for this forum.
I am looking to have a query that can pull the values of certain columns from certain tables. I would like this to be as flexible as possible however so as we add more of these tables the query wouldn't need to be changed. So essentially something like this:
obviously this does not work and my SQL coding experience is a bit limited unfortunately. I am sure this is a logic approach problem but I can't seem to get my own head past my preconceived concept here. Could anyone point me in the right direction perchance?
I am looking to have a query that can pull the values of certain columns from certain tables. I would like this to be as flexible as possible however so as we add more of these tables the query wouldn't need to be changed. So essentially something like this:
Code: Select all
Select (SELECT COLUMN_NAME
FROM _V_SYS_COLUMNS
WHERE
TABLE_NAME like 'XFMD%'
AND SCHEMA = 'ADMIN'
AND COLUMN_NAME like '%BK') as Column_Name
FROM (SELECT DISTINCT TABLE_NAME
FROM _V_SYS_COLUMNS
WHERE
TABLE_NAME like 'XFMD%'
AND DATABASE = 'VALHALLA'
AND SCHEMA = 'ADMIN') as Source_Table