日期:2014-05-18  浏览次数:20606 次

这是哪里错了,看了很久,求情帮忙!
declare   @table_name   varchar(20)
declare   @strSql   nvarchar(4000)
declare   @rscount   int
declare   table_cursor   CURSOR   For
select   [name]   from   sysobjects   where   type= 'u '
open   table_cursor
fetch   next   from   table_cursor   into   @table_name
WHILE   @@FETCH_STATUS   =   0
  begin
    set   @strSql= 'select   @rscount=count(0)   from   '+@table_name
        declare   cursor_temp   CURSOR   For
        exec   sp_executesql   @strSql
        set   @rscount=@@rowcount
        open   cursor_temp
        fetch   next   from   cursor_temp   into   @rscount
        close   cursor_temp
    insert   into   DBuser_Web2006.backcup([name],rscount)   values   (@table_name,dbuser_web2006.getcount(@table_name))
    fetch   next   from   table_cursor   into   @table_name  
  end
CLOSE   table_cursor
DEALLOCATE   table_cursor


exec   sp_executesql   @strSql   语法错误!

------解决方案--------------------
--try
declare @table_name varchar(20)
declare @strSql nvarchar(4000)
declare @rscount int
declare table_cursor CURSOR For
select [name] from sysobjects where type= 'u '
open table_cursor
fetch next from table_cursor into @table_name
WHILE @@FETCH_STATUS = 0
begin
set @strSql= 'select @rscount=count(0) from '+@table_name
exec sp_executesql @strSql,N '@rscount int out ',@rscount out
insert into DBuser_Web2006.dbo.backcup([name],rscount) values (@table_name,@rscount)
fetch next from table_cursor into @table_name
end
CLOSE table_cursor
DEALLOCATE table_cursor