数据库结构为:n张相同结构的表  表名为T_table1,T_table2.....T_table n
我想写如下的一个存储过程如下:create procedure   TableSlect(
     @sTable [char] (20),
)
as
begin
select * form @sTable
end
这样这个存储过程就可以试用所有的表了
不知道这样行不行,
如果不行那么如果要完成这个功能需要怎么做???

解决方案 »

  1.   

    create procedure TableSlect(
      @sTable [char] (20)
    )
    as
    begin
    exec('select * form '+@sTable)
    end
      

  2.   

    楼主这样写存储过程也没起到什么作用,如果你能传入参数@sTable那么肯定知道表名,直接select 不就可以呢?问题是:楼主究竟想要做什么呢?