How to pass schema as parameter to a stored procedure in sql server?

后端 未结 1 1109
[愿得一人]
[愿得一人] 2021-01-03 05:32

I have a stored procedure to select a list of data based on two tables. The first table is a fixed one: CO.Country. But the second table can be one of a number

相关标签:
1条回答
  • 2021-01-03 06:03

    Use DynamicSql

    Try like this

    CREATE PROCEDURE proc_name
       @schema VARCHAR(25)
    AS
    
    DECLARE @Query VARCHAR(1000)
    SET @query='SELECT * FROM' +@schema +'.Location'
    EXECUTE(@query)
    
    0 讨论(0)
提交回复
热议问题