简单过程将表名作为参数并显示其内容

时间:2017-04-18 15:16:57

标签: sql-server stored-procedures

create procedure showMe @Tname varchar(30)
AS
BEGIN
    select * from @Tname        -->>am i violate some rules !!
END ;
------------------------------------------ 

@JNevill我想我得到了你的想法,但不是很正确。

      create procedure showMe @Tname varchar(30)
      AS
      BEGIN
      declare @SS varchar(40) = 'Select * from '
      declare @CC varchar(80)
        @CC = @SS + @Tname  
        sp_executesql @CC
     END ;

我找到了解决方案.......

  create procedure showMe @Tname varchar(30)
  AS
  BEGIN
    EXEC('select * from ' + @Tname)
  END ;

0 个答案:

没有答案