Hello Everyone,
I have declared a Cursor to get table names and no of columns in that tables based on column names.Please find the below query table name is not get inserted.Please suggest.
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