存储过程中alter proc getRow(
 @id varchar(10)
)
as
begin
  declare @tt varchar(1000)
  --@tt 是表名
  select @tt = 'Row'+ @id
  select * from @tt
end编译说我 @tt是表变量
我用 select * from '+@tt+' 编译也报错那这个应该是怎么写的?

解决方案 »

  1.   

    alter proc getRow( @id varchar(10))
    as
    begin
      declare @tt varchar(1000)
      --@tt 是表名
      select @tt = 'Row'+ @id
     exec('select * from '+@tt)
    end
      

  2.   

    alter proc getRow( @id varchar(10))
    as
    begin
      declare @tt varchar(1000)
      --@tt 是表名
      select @tt = 'Row'+ @id 
      print @tt --不知道你这个是什么意思
     exec('select * from '+@tt)
    end
      

  3.   

    exec('select * from '+@tt)
    --或者
    exec sp_executesql 'select * from '+@tt动态sql