Stored procedure, pass table name as a parameter

后端 未结 5 1762
小鲜肉
小鲜肉 2020-12-12 02:15

I have about half a dozen generic, but fairly complex stored procedures and functions that I would like to use in a more generic fashion.

Ideally I\'d like to be abl

5条回答
  •  囚心锁ツ
    2020-12-12 02:50

    ALTER procedure [dbo].[test](@table_name varchar(max))
     AS
     BEGIN
      declare @tablename varchar(max)=@table_name;
      declare @statement varchar(max);
      set @statement = 'Select * from ' + @tablename;
      execute (@statement);
     END
    

提交回复
热议问题