|
Posted by db55 on 05/16/06 19:48
I have >200 tables and I want to create a table that lists the name of
each table, the number of records, and the number of locations within
the table.
I've created a cursor to do this but it doesn't like it. I get the
following error.
Invalid column name '<tablename>'.
Here's my script
DECLARE @tbl varchar(100)
DECLARE @sql varchar(1000)
-- Insert statements for procedure here
declare c_table cursor for
select table_name from INFORMATION_SCHEMA.TABLES where table_type =
'base table' order by table_name
open c_table
fetch next from c_table into @tbl
while (@@fetch_status = 0)
begin
set @SQL = 'INSERT INTO [zzTable_Status]
SELECT ('+ @tbl +') as tblname, count(distinct station__no),
count(station__no)
FROM [bronze_views].'+@tbl+''
exec (@SQL)
Print @tbl + ' Updated'
fetch next from c_table into @tbl
end
close c_table
deallocate c_table
Any help is appreciated...
Navigation:
[Reply to this message]
|