我一直在試圖找出每個表中被禁用的行的總數。 在我的數據庫中,我有20列IsActive列的表。查詢根據列名查找表的行數?
我曾嘗試下面的光標,但它越來越錯誤說無效的對象名稱@Namee。
Create table #t
(
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
insert into #t Select count(*) from @Namee where isactive=0
Fetch Next From @Getname into @Namee
End
Close @GetName
Deallocate @GetName
select * from #t
感謝百萬Preet的工作。 – Simhadri 2010-09-15 21:57:18