我正在使用 SQL Server 2008。我的存储过程必须传递动态数据库名称并将列值存储到变量中
ALTER PROCEDURE [dbo].[proc_testproc](@mUserId int)
AS
declare @logCreate BIT;
declare @dbname sysname;
set @dbname = 'finaldb'
exec('SELECT ua.LogCreate AS ' + @logCreate + ' from '+ @dbname
+ 'dbo.User_Access as ua where ua.UserId=' + @mUserId + ')
IF @logCreate = 1
--- Below some insertion happens based on the select query output--
谁能帮助我如何传递动态数据库名称并将值存储到变量中?