Stored procedure, pass table name as a parameter

后端 未结 5 1778
小鲜肉
小鲜肉 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:36

    You can use dynamic Sql, but check that the object exists first unless you can 100% trust the source of that parameter. It's likely that there will be a performance hit as SQL server won't be able to re-use the same execution plan for different parameters.

    IF OBJECT_ID(@tablename, N'U') IS NOT NULL
    BEGIN 
        --dynamic sql
    END
    

提交回复
热议问题