Evaluate in T-SQL

后端 未结 11 2198
悲&欢浪女
悲&欢浪女 2020-12-17 23:42

I\'ve got a stored procedure that allows an IN parameter specify what database to use. I then use a pre-decided table in that database for a query. The problem I\'m having i

11条回答
  •  春和景丽
    2020-12-18 00:17

    try the sp_executesql built in function. You can basically build up your SQL string in your proc, then call

    exec sp_executesql @SQLString.
    
    DECLARE @SQLString nvarchar(max)
    SELECT @SQLString = '
    SELECT *
    FROM  ' +  @TableName 
    
    EXEC sp_executesql @SQLString
    

提交回复
热议问题