Archives of the TeradataForum
Message Posted: Fri, 20 Aug 2004 @ 03:01:57 GMT
Subj: | | Re: How to retrieve tablename and its count dynamically |
|
From: | | McCall, Glenn David |
Try running this query, then paste the output back into your query tool and run it. You will need to manually remove the last union all and can
optionally add an 'order by 1' to sort the output.
select 'select ''' || trim (both from tablename) || ''' (varchar(30)),
count(*) from ' || trim (both from tablename) || ' union all'
from dbc.tables
where databasename = 'yourdatabase' and
tablekind = 't';
The above query will produce something like this which you can submit to TD:
select 'kpi_event_base_org' (varchar(30)), count(*) from kpi_event_base_org
union all
select 'GOAL_COLOR_CONTROL' (varchar(30)), count(*) from GOAL_COLOR_CONTROL
union all
select 'kpi_initiative_org' (varchar(30)), count(*) from kpi_initiative_org
union all
select 'KPI_COLOR_CONTROL' (varchar(30)), count(*) from KPI_COLOR_CONTROL
union all
Don't forget to get rid of the last union all (and optionally add a order by 1 to this output.
Hope this helps.
Glenn Mc
|