我已經聲明瞭一個Cursor來根據列名得到表名和列中的列號。請發現下面的查詢表名沒有被插入。請建議SQL Query根據列名得到表名和行數「
Create table #t
(
tabname varchar(500),
NoOfRows bigint,
)
Declare @Namee Varchar(500)
Declare @GetName Cursor
Set @Getname = Cursor for
Select table_name from information_Schema.columns
where column_name='isactive'Open @Getname
Fetch Next From @Getname into @Namee
While @@Fetch_Status=0
Begin
--Print @Namee
insert into #t(tabname) SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME =' + @Namee + '
exec ('insert into #t(NoOfRows) Select count(*) from ' + @Namee + ' where isactive=0')
Fetch Next From @Getname into @Namee
End
Close @GetName
Deallocate @GetName
select * from #t
感謝OMG的工作。 – Simhadri 2010-09-21 17:25:28