washaw
Programmer
- Feb 13, 2008
- 48
hello,
I have a table tbl (have identity column) contains name of tables, and need to do count the number of records for each table
--code
it is erroring out invalid object name #tmpTable
is it possible to use temporary table in dynamic sql if not what should I do
Thanks
I have a table tbl (have identity column) contains name of tables, and need to do count the number of records for each table
--code
Code:
declare @int int, @str varchar(1000), @tblName varchar(100)
select @int = min(id) from tbl
while @int is not null
begin
select @tblName = tblName from tbl where id = @id
set @str = 'select * into #tmpTable from ' + @tableName
select count(*) from #tmpTable
select @int = min(id) from tbl where id > @id
drop table #tmpTable
end
it is erroring out invalid object name #tmpTable
is it possible to use temporary table in dynamic sql if not what should I do
Thanks