Greetings
I have been trying to write a script that will list out the size of each
user table in a specified DB. I am running into a scoping problem when
trying to format my display. I am sure there are several ways to derive the
results. My method won't allow me to
select count(*) from @tab_var
as it barks that I must declare the variable @tab_var.
-- start of script Should be able to copy and paste into QA
use fin_temp2
declare @tab_var varchar(50)
declare @tab_count int
declare @count int
declare @count_val int
select
@count = 0
declare c cursor for
select name from [Fin_Temp2].dbo.sysobjects
where type = N'U' order by name
open c
fetch c into
@tab_var
-- set @count_val = 'select count(*) from ' + @tab_var
-- select count(*) from @tab_var
set @count_val = exec ('select count(*) from ' + @tab_var) -- <<<===
select @count,@tab_var,@count_val -- <<<=== What I would
like to do so results would be displayed on one line
while @@fetch_status = 0
begin
set @count = @count + 1
fetch c into
@tab_var
select @count, @tab_var
end
close c
deallocate c