sfriedman451
Technical User
I am trying to create a SPROC to get row counts from all the tables in a database. To experiment I've created one that works (or I should say doesn't work) with the PUBS database.
Use Pubs
GO
Create Table #Tblnames (tblename varchar(60))
GO
Select name into #Tblenames from sysobjects where xtype = 'U'
Select name from #Tblenames
Declare C1 cursor FOR Select name from #Tblenames FOR READ ONLY
Open C1
Declare @tbl varchar(65)
Fetch c1 into @tbl
Select @tbl
Select count (*) from @tbl
Next c1
DeAllocate c1
It seems to have a problem withthe Select count (*) from @tlb - it tells me @tbl is not defined. Can I use a variable here?
Is there a better way to do this type of operation?
Thanks in advance
Steve
Use Pubs
GO
Create Table #Tblnames (tblename varchar(60))
GO
Select name into #Tblenames from sysobjects where xtype = 'U'
Select name from #Tblenames
Declare C1 cursor FOR Select name from #Tblenames FOR READ ONLY
Open C1
Declare @tbl varchar(65)
Fetch c1 into @tbl
Select @tbl
Select count (*) from @tbl
Next c1
DeAllocate c1
It seems to have a problem withthe Select count (*) from @tlb - it tells me @tbl is not defined. Can I use a variable here?
Is there a better way to do this type of operation?
Thanks in advance
Steve